简体   繁体   中英

Previous slide and auto play Jquery slider,

I`m trying to figure out how to make a jquery slider, I got 2 main problems.

LIVE DEMO

PROBLEM 1 Previous slide. Its going to the previous slide, but after clickCount == slider.length, it just disapears.

//previous

$("#previous").click(function(){
     if(clickCount < slider.length)
           slider.eq(clickCount--).hide();

     if(clickCount == slider.length)
         clickCount = 0;
      slider.eq(clickCount).show();
 }) ; 

PROBLEM 2 Auto Play My auto-play logic is not working...

//autoplay


$(document).ready(function(){
var presentSlide = 0

     if(presentSlide < slider.length)
           slider.eq(presentSlide++).fadeOut(600);
     if(presentSlide == slider.length)
         presentSlide = 0;
      slider.eq(clickCount).fadeIn(600);
 }) ; 

Problem 1:

You have to check clickCount different than the next button:

$("#previous").click(function(){
     if(clickCount >= 0) 
           slider.eq(clickCount--).hide();              
     if(clickCount < 0)
         clickCount = slider.length-1;
      slider.eq(clickCount).show();
 }) ; 

Problem 2:

For the auto-play, why don't you just click the next button every X seconds?

$(document).ready(function(){
    setInterval(function(){
             $("#next").click();
         },5000);  //every 5000 ms (5 seconds)
 }) ;  

FIDDLE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM