JQuery: Trouble with simple slideshow

孤者浪人 提交于 2019-12-12 01:12:56

问题


I'm having trouble with a super simple slideshow I'm trying to make. I can't figure out why it won't work. The first picture shows up but it does not cycle through.

Here is the JSFiddle: http://jsfiddle.net/cydonknight/kyhxy/

and the JQuery:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

        <script type="text/javascript">
        $(document).ready(function(){
            setInterval("rotateImages()", 2000   );
        });
        function rotateImages(){
            var $onCurrent= $('#imageSlider div.current') ;


            var $onNext= $onCurrent.next().length ? $onCurrent.next();
                : $('#imageSlider div:first');

            if (!onNext.length )
                onNext=$("#imageSlider div:first");

            $onCurrent.addClass('previous');
            $onNext.css({opacity: 0.0}).addClass('current').animate({opacity:1.0}, 2000, function() {
                    $onCurrent.removeClass(' previous');
                    });


            }

    </script>

Any help would be greatly appreciated!


回答1:


It is working now. I did lot of changes actually.

your updated fiddle

    setInterval(rotateImages, 2000);

function rotateImages()
{
var $onCurrent= $('#imageSlider div.current') ;
var $onNext= $onCurrent.next().length ? $onCurrent.next() : $('#imageSlider div:first');   

if (!$onNext.length )
    $onNext=$("#imageSlider div:first");

$("#imageSlider div").removeClass("current").css("opacity", 0);
$onNext.addClass('current').animate({opacity:1.0}, 1000);
}


来源:https://stackoverflow.com/questions/13716970/jquery-trouble-with-simple-slideshow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!