将单击代码更改为自动循环版本

时间:2013-04-18 10:37:28

标签: jquery slideshow

我有这段代码:

function slideshow_animateClick(){
    slideshowItem_position = 0 - (slideshowItem_place * 1920);
    $('#slideshowContent').stop().animate({'left':slideshowItem_position + 'px'}, 1000, 'swing');
  }

...这是水平幻灯片中的左/右按钮单击功能。

我需要将其复制到loopable版本。基本上我希望幻灯片可以单独播放,直到单击左/右按钮。一旦发生这种情况,在幻灯片重新恢复自动播放之后设置某种空闲时间条件会很不错。

完整背景 - Fiddle

感谢名单。

佩德罗

1 个答案:

答案 0 :(得分:0)

编辑:在这里添加小提琴:http://jsfiddle.net/jnS3H/12/包含您的代码和修复程序。

要执行间隔计时器,您可以执行以下操作:

//create a function to handle the auto rotate
function autoRotate() {
    //code here for what happens every n seconds
}

//create a function that holds the interval to do an auto rotate push
function rotate(){
    var startRotate = setInterval(function(){  //Start the autorotate on load to rotate every 2 seconds.      
        autoRotate();
    }, 2000);
}

$('.rightarrow, .leftarrow').click(function(){
    clearInterval(startRotate);  //Stops the auto-animation
    clearTimeout(startAgain);   //Stops the starting again - incase you click again, it resets the timeout
    //write some code here to do something when you click on the right arrow
    var startAgain = setTimeout(function(){  //Then create a timeout to start rotating again after you click
        rotate();
    }, 2000);
});

$(document).load(function(){
    rotate();
});

这当然是非常松散的代码,你必须填写空白并测试它,但我相信校长是正确的。