0

Still somewhat new at jQuery, I am using the following to automatically scroll a div with the class name of .scroller when the page loads.

$(".scroller").delay(2000).animate({ scrollTop: $('.scroller')[0].scrollHeight}, 50000);

However I would like to stop any scrolling upon hover over that div and start it back when hovering out.

Any thoughts on how to achieve this or should I be using something other than scrollTop for this?

Thanks, Chris

4

1 回答 1

3

要在条件下停止动画,您可以使用:$(".scroller").stop()

然后,像你一样重新开始滚动,没有延迟。

http://api.jquery.com/stop/

$("#myDiv").hover(
    function(){
        $(".scroller").stop();
    },
    function(){
        $(".scroller").animate({ scrollTop: $('.scroller')[0].scrollHeight}, 50000);
    }
);
于 2013-01-04T20:33:53.550 回答