首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何自动播放这个javascript滑块?

问如何自动播放这个javascript滑块?
EN

Stack Overflow用户
提问于 2013-04-04 16:24:13
回答 3查看 3.2K关注 0票数 0

我发现了这个漂亮的js滑块,它可以通过点击单选按钮,选择要查看的幻灯片来工作。

我希望它能自动播放幻灯片,并给它一个幻灯片和过渡的时间,但老实说,我不确定该把这些值放在哪里。

我看过关于类似问题的其他问题,但找不到我的问题的正确答案。帮帮忙,好吗?

代码语言:javascript
复制
<script type="text/javascript">
    $(document).ready(function () {

        var showCaseItems = $('.show-case-item').hide();

        var splashes = $('.splash').hide();
        //get each image for each slide and set it as a background of the slide
        //            splashes.each(function () {
        //                var img = $(this).find('img');
        //                var imgSrc = img.attr('src');
        //                img.css('visibility', 'hidden');
        //                $(this).css({ 'background-image': 'url(' + imgSrc + ')', 'background-repeat': 'no-repeat' });
        //            });

        splashes.eq(0).show();
        showCaseItems.eq(0).show();

        var prevIndex = -1;
        var nextIndex = 0;
        var currentIndex = 0;

        $('#banner-pagination li a').click(function () {

            nextIndex = parseInt($(this).attr('rel'));

            if (nextIndex != currentIndex) {
                $('#banner-pagination li a').html('<img src="assets/img/slidedot.png" alt="slide"/>');
                $(this).html('<img src="assets/img/slidedot-active.png" alt="slide"/>');
                currentIndex = nextIndex;
                if (prevIndex < 0) prevIndex = 0;

                splashes.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
                    $(this).hide();
                });
                splashes.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 500, function () { });

                showCaseItems.eq(prevIndex).css({ opacity: 1 }).animate({ opacity: 0 }, 500, function () {
                    $(this).hide();
                    showCaseItems.eq(nextIndex).show().css({ opacity: 0 }).animate({ opacity: 1 }, 200, function () { });
                });

                prevIndex = nextIndex;
            }

            return false;
        });

    });
</script>
EN

回答 3

Stack Overflow用户

发布于 2013-04-04 17:08:29

您可以使用jquery和setTimeout

代码语言:javascript
复制
setTimeout(function() {$('#banner-pagination li a').trigger('click');}, 1500);

此代码将每1.5秒循环一次,并触发对#banner-pagination li a的单击

票数 1
EN

Stack Overflow用户

发布于 2013-04-04 18:05:15

您可以使用jquery触发器事件并强制单击单选按钮单击事件

点击$(‘#foo’).trigger(‘

’);

http://api.jquery.com/trigger/

票数 0
EN

Stack Overflow用户

发布于 2013-08-16 17:16:57

代码语言:javascript
复制
setInterval(function() 
  {$('#banner-pagination li a[rel='+((currentIndex+1)%3)+']').trigger('click');},5000);

谢谢

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15806044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档