Use a slider handle to drag through image slideshow

Boris Hansen

I want my website visitors to be able to use a jQuery slider to 'drag' their way through a sequence of images. Only one image is shown at a time, and when the user drags the slider handle left and right, the shown image changes to the next/previous in the sequence. Additionally, and this is the tricky part, I want the new image to fade in on top of the previous image.

I have the slider code working, using the jQuery slider:

$( "#mySlider" ).slider({
range: "max",
min: 1,
max: 10,
value: 1,
slide: function( event, ui ) {
    // CODE THAT MAKES THE NEW IMAGE FADE IN
}
});

Currently, my plan is to actually have all images in the HTML in separate DIVs that overlay each other and with opacity 0. Dragging the handle would put the relevant div on top and fade it in.

Any ideas how to do this?

daker

I would do something like this (link to JSFiddle)

html

<div id="gallery">
    <img src="http://i.imgur.com/SfzW1.jpg" class="abs pic1" />
    <img src="http://i.imgur.com/hsVyi.jpg" class="abs pic2" />
    <img src="http://i.imgur.com/RJVm9.jpg" class="abs pic3" />
    <img src="http://i.imgur.com/dw00y.jpg" class="abs pic4" />
</div>

and the css

#gallery{
    position: relative;
}

img {
    display:none;
    width: 200px;
    height: 100px;
    z-index:0;
}


.pic1{
    display:inline;
}
.abs{
    position: absolute;
    top:0;
    left:0;
}

javaScript/jquery

$( "#mySlider" ).slider({
range: "max",
min: 1,
max: 4,
value: 1,
slide: function( event, ui ) {
    var pic_num = ui.value;
    var new_image_elm = $("#gallery img.pic"+pic_num);
    var old_image_elm = $("#gallery img:visible");

    if(new_image_elm != null){
        var zIndex = parseInt(old_image_elm.css('z-index'));
        new_image_elm.css('z-index', zIndex+1);        
        new_image_elm.fadeIn( "slow", function() {
            // Animation complete
            old_image_elm.hide();
        });         
    }
}
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

Rotating image based on drag handle in flutter

From Dev

jQuery drag and drop image to textarea handle event

From Dev

Slideshow flickering image on :hover

From Dev

Drag image with button as image's handle

From Dev

jqueryUI multi handle and image as handle slider

From Dev

How to use image slider in swing?

From Dev

Slider Slideshow Using jQuery

From Dev

Dynamic run through a row of img tags (image slider)

From Dev

Drag drop with handle

From Dev

Disable mouse drag on slider

From Dev

How to use glide library for slider image in android

From Dev

Image slideshow with movepy

From Dev

how to use shadowBox as simple image slider without popup effects?

From Dev

Drag image with button as image's handle

From Dev

Use a slider handle to drag through image slideshow

From Dev

Looking for slider plugin can use image from url

From Dev

image slideshow not working

From Dev

Custom jQuery slider repeating the same image - not incrementing through 'i'

From Dev

Manage SM Dynamic Slideshow slider effects

From Dev

why use setTimeout on this slideshow?

From Dev

Why my left drag/slider is working but the right drag/slider not working

From Dev

How to use glide library for slider image in android

From Dev

How to drag and drop a slider in protractor?

From Dev

How to use a Matlab GUI slider to display image timeframes

From Dev

Slideshow image from JSON

From Dev

Background-Image slideshow?

From Dev

Use first column for drag image in NSTableView

From Dev

Image Slideshow using JFrame

From Dev

SlideShow Image in XamarinAndroid