【问题标题】:auto increment image in Image slider in JQueryJQuery中图像滑块中的自动增量图像
【发布时间】:2013-10-19 17:32:27
【问题描述】:

我试图让 JQuery 中的图像滑块在大约 2 秒后移动到下一个图像,我尝试创建一个应该在文档加载时执行此操作的函数,但经过大约 3 小时的详尽谷歌搜索后我根本无法弄清楚.

是否有一个 JQuery 类可以做到这一点,因为我找不到......

到目前为止我的代码:

        $('.slider img:first').addClass('active');                    

        var imagewidth = $('.visible-area').width();                  
        var totalimages = $('.slider img').size();                    
        var sliderwidth = imagewidth * totalimages;                   
        $('.slider').css({'width': sliderwidth}); 


        function autoImage()
        {
            nextImage();
        }

        function nextImage()
        {
            $active = $('.slider img.active').prev();                 
            if ($active.length==0){                                    
                $active = $('.slider img:last');
            }
            $('.slider img').removeClass('active');                   
            $active.addClass('active');                               

            var count = $active.attr('alt') -1;                       
            var sliderposition = count * imagewidth;                  
            $('.slider').hide();
            $('.slider').animate({'left': -sliderposition}, 500).fadeIn(1000);  
    }

谢谢

【问题讨论】:

标签: javascript jquery html css


【解决方案1】:

我相信你的变量声明有问题。

来自 jQuery Api 文档:

.size() 方法从 jQuery 1.8 开始被弃用。使用 .length 属性。

所以用它代替var totalimages

尝试登录多个断点以隔离有问题的区域

【讨论】:

  • 感谢您的提醒
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-11
  • 1970-01-01
相关资源
最近更新 更多