开发者

Stop jQuery from scrolling when element changes out of the view

开发者 https://www.devze.com 2023-01-26 15:18 出处:网络
I have a very long page. At the top I have a banner div with a background-image that changes every 10 seconds through a timer.

I have a very long page. At the top I have a banner div with a background-image that changes every 10 seconds through a timer.

When you scroll down to see the content "below the fold", jQuery then scrolls to the top to show the new banner image.

This is very disruptive -how could I stop jQuery from scrolling to the top? Thank you.

timer = setTimeout(function() {
    $('div#banner'开发者_运维问答).css('background-image', 'url(...)'; }
    // set timeOut again.
, 10000);


FYI -As the comments points out, the issue was not caused by the "css" function but by a "fadeOut" "fadeIn" effect. Hope this helps somebody else. Thank you.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号