0

Im trying to get an image slider in JQuery to move to the next image after around 2 seconds, ive tried creating a function that should do this on document load but i cant figure it out at all after about 3 hours of exhaustive Googling.

Is there a JQuery class which does this cos i cant find one...

my code for this so far :

        $('.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);  
    }

thanks

4

1 回答 1

1

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

来自 jQuery Api 文档:

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

所以用它代替var totalimages

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

于 2013-10-19T17:41:03.273 回答