jQuery loop function and start from beginning - flip function

懵懂的女人 提交于 2019-12-25 08:56:40

问题


here is the code: http://jsfiddle.net/VW8V5/1/

When hover it should start looping but end of the loop somehow it shows only img3 and img4 (looping img3 to img4), it should start from the beginning. When hover out it should stop at img1.


回答1:


This will cycle through all four images. I'm not sure what you were trying to accomplish when you stop hovering other that to stop the cycle of the images.

/* FOR PEOPLE LIST ITEMS */
$(".box a").hover(
    function () {
        var self = $(this);
        self.data("hover", true);
        function flip() {
            var top = self.closest(".box");
            var next = top.find(".current").next("img");
            if (!next.length) {
                next = top.find("img:first");
            }
            top.find("img").hide().removeClass("current");
            next.addClass("current").show().flip({
                direction:'tb',
                speed: 200,
                onEnd: function(){
                    if (self.data("hover")) {
                        setTimeout(flip,500);
                    } else {
                        top.find(".hidden").fadeOut("slow");
                        top.find(".active").fadeIn("slow");
                    }
                }
            })
        }
        flip();

    }, 
    function () {
        $(this).data("hover", false);
    }
);

Working demo here: http://jsfiddle.net/jfriend00/hQnXm/



来源:https://stackoverflow.com/questions/9847145/jquery-loop-function-and-start-from-beginning-flip-function

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