Search code examples
jqueryjquery-ui-slider

How do I get jQuery Slider Widget to show and fade between images?


I found a concept that is very close to what I need to do: use a slider to fade between images.

Here is the working example on jSFiddle.

Here is my test page: http://energync.ehclients.com/slider.html

I brought the code in but it is not working correctly for me.

Here is the HTML:

<div class="ui-corner-all" id="sliderContent">     
<div class="viewer ui-corner-all">
<div class="content-conveyor ui-helper-clearfix" style="width: 2128px;">

<div class="item">
<h2>Omega Nebula</h2>
<img alt="Omega Nebula" src="http://d2o0t5hpnwv4c1.cloudfront.net/377_slider/slider_sourcefiles/images/omega.jpg">
</div>

<div class="item">
<h2>Rosette Nebula</h2>
<img alt="Rosette Nebula" src="http://d2o0t5hpnwv4c1.cloudfront.net/377_slider/slider_sourcefiles/images/rosette.jpg">
</div>
</div>
</div>
</div>
<div id="slider"></div>

Here is the CSS

#sliderContent .item { display: none; position: absolute; }

Here is the jQuery

$(function() {
$('#sliderContent .item:first').addClass('shown').show();
$("#slider").slider({
value: 0,
min: 0,
max: $('#sliderContent .item').size(),
step: 1
}).bind("slidechange", function(event, ui) {
var newIndex = $("#slider").slider("value");
var oldIndex = $('#sliderContent .item').index('.shown');
if (newIndex != oldIndex) {
$('.shown').fadeOut().removeClass('shown');
$('#sliderContent .item').eq(newIndex).fadeIn().addClass('shown');
}
});
});

I would appreciate some help getting this to work correctly.


Solution

  • Your fiddle is working fine for me. Do you want the image to change when the user is still holding the slider? (not only when it's released)