如何让这个jQuery滑块停止?

时间:2012-10-11 11:05:03

标签: jquery slider

我有问题。我使用这个jQuery脚本(http://musca.se/full-window-width-jquery-tools-content-slider-demo/)来滑动我的投资组合的东西,但我根本不是jQuery的专业人士很多搜索我现在问你。当我按prev或next时,如何让滑块停止滑动?

这是代码的样子:

$(function() {
        // Sets the slides width on page load
        var i = $(window).width();
        if (i > 319){ $('#items > div').css({ width: i }); }
        // Scrollable and navigator plugin settings.
        $("#slider").scrollable({ circular: true, touch: true, easing: 'easeInQuart', speed: 900}).navigator({ navi: '#navigation' }).autoscroll({ autoplay: true, autopause:false, interval: 2000 });

        // Window resize code
        window.api = $("#slider").data("scrollable");
        $(window).resize(function() {
            var a = window.api.getIndex();
            var w = $(window).width();
            if (w > 319) {
                var l = a * w
                $('#items').css({ left: + - +l });
                $('#items > div').css({ width: w });
            } else {
                $('#items > div').css({ width: 300 });
            }
        });
    });

我的导航按钮如下所示:

<div id="navigation-wrapper">
    <span class="prev lefty"><img src="img/left.png" /></span>
    <span class="next righty"><img src="img/right.png" /></span>
</div>

我真的很感谢你的帮助!

1 个答案:

答案 0 :(得分:0)

如果在调用之前将超时声明为变量:

var st;

$('.prev').on('click',function(){
    st = setTimeout("$('#slider')", 999999);
});

你可以这样清除它:

clearTimeout(st);

编辑:

看到前面的代码是基于一个过时的例子,你可以试试这个:

$('#navigation-wrapper').on('click', 'span', function(){
    $('#slider').autoscroll({ autoplay: false, autopause:false, interval: 0 });
}

这应该有希望重新初始化滑块,其自动播放值为false,这意味着它将自动停止旋转。但是,我不熟悉这个插件,所以这是最好的猜测。希望它适合你。

相关问题