jquery - How can I make this Image fade-in-fade-out loop continuously within bxslider? -


i've followed tutorial build simple image fader: http://www.mustbebuilt.co.uk/jquery-introduction/building-a-simple-image-fader/

but reason mine not loop infinitely bxslider... after last/third image fades, stops. if add 1 more image (a 4th), it's fine. if remove bxslider call, works. ideas why?

here's test page:

image fader test page

the html:

        <ul class="rotating-images">             <li><img src="img/girl1.jpg"></li>             <li><img src="img/girl2.jpg"></li>             <li><img src="img/girl3.jpg"></li>         </ul> 

the js:

$(document).ready(function(){   $('.bxslider').bxslider(); });  var fadeduration=2000; var displaytime=4000; var currentindex=1; var nextindex=1;     $(document).ready(function() {               $('ul.rotating-images li').css({opacity: 0.0});         $("'ul.rotating-images li:nth-child("+nextindex+")'").addclass('show').animate({opacity: 1.0},fadeduration);         /* setinterval("nextslide()",displaytime);*/         var timer = setinterval('nextslide()',displaytime);     });     function nextslide(){         nextindex = currentindex+1;         if(nextindex> $('ul.rotating-images li').length)         {          nextindex =1;         }         $("'ul.rotating-images li:nth-child("+nextindex+")'").addclass('show').animate({opacity: 1.0},fadeduration);         $("'ul.rotating-images li:nth-child("+currentindex+")'").animate({opacity: 0.0},fadeduration).removeclass('show');         currentindex = nextindex;     }; 

the css:

.rotating-images{     padding:0;     margin:0;     list-style: none;     position:relative;   } ul.rotating-images li {     position:absolute;     left:0px;     top:0px;     display:inline;     width: 343px;     height: 479px; } ul.rotating-images li.show {     z-index:500;     } 

thanks!

you've got quotes(') around selector. remove them , work.

change

$("'ul.rotating-images li:nth-child("+nextindex+")'") $("'ul.rotating-images li:nth-child("+currentindex+")'") 

to

 $("ul.rotating-images li:nth-child("+nextindex+")")  $("ul.rotating-images li:nth-child("+currentindex+")") 

working example : https://jsfiddle.net/dinomyte/6x80vabm/2/


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -