关于滑块javascript的点击回合停止自动播放

时间:2012-11-29 11:24:56

标签: javascript jquery slideshow

我使用了这个site的圆形滑块。

如果我鼠标悬停在幻灯片放映上,则自动旋转停止。我需要stop auto play on click链接Stop auto play。{/ p>

我的HTML代码:

<div id="carousel">
    <a href="#"><img src="image_main1.jpg" alt=""></a>
    <a href="#" ><img src="image_main2.jpg" alt=""></a>
    <a href="#" ><img src="image_main3.jpg" alt=""></a>
</div>

<div id="carousel-controls">
    <span class="control current"><img src="video_thumb1.jpg" alt=""></span>
    <span class="control"><img src="video_thumb.jpg2" alt=""></span>
    <span class="control"><img src="video_thumb.jpg3" alt=""></span>
</div>
<div><a href="#">Stop auto play</a></div>

我的剧本:

(function($) {

var $descriptions = $('#carousel-descriptions').children('li'),
    $controls = $('#carousel-controls').find('span'),
    $carousel = $('#carousel')
        .roundabout({childSelector:"a", minOpacity:1, autoplay:true, autoplayDuration:5000, autoplayPauseOnHover:true })
        .on('focus', 'a', function() {
            var slideNum = $carousel.roundabout("getChildInFocus");

            $descriptions.add($controls).removeClass('current');
            $($descriptions.get(slideNum)).addClass('current');
            $($controls.get(slideNum)).addClass('current');

        });


$controls.on('click dblclick', function() {
    var slideNum = -1,
        i = 0, len = $controls.length;

    for (; i<len; i++) {
        if (this === $controls.get(i)) {
            slideNum = i;
            break;
        }
    }

    if (slideNum >= 0) {
        $controls.removeClass('current');
        $(this).addClass('current');
        $carousel.roundabout('animateToChild', slideNum);
    }
});

}(jQuery));

怎么做?

2 个答案:

答案 0 :(得分:1)

在API页面(http://fredhq.com/projects/roundabout#/api)中,btnStopAutoplay是“页面元素的jQuery选择器,单击时将停止Roundabout的自动播放功能(如果它正在播放) 。“

因此,首先添加一个ID,以便可以选择

<div><a href="#" id="carouselstop">Stop auto play</a></div>

然后,更新您的Javascript以包含btnStopAutoplay:

.roundabout({childSelector:"a", minOpacity:1, autoplay:true, autoplayDuration:5000, autoplayPauseOnHover:true, btnStopAutoplay:"#carouselstop" })

答案 1 :(得分:0)

您可以通过将布尔值设置为false

来停止自动播放
<div><a href="#" onclick='$('#carousel').roundabout({autoplay: false});'>Stop auto play</a></div>

See this link for reference