开发者

windows scroll smooth effect

I have the following code which centers the popup when we scroll , it quickly re-positions itselef to center. How to get the smoothing effect as if it is dropping very smooth.

 $(window).scroll(function () {

        var top = ($(window).height() - $('.myPopUp').height()) / 2 + $(wi开发者_运维知识库ndow).scrollTop();
        $('.myPopUp').animate({ top: top }, 10);

});

I tried to play around with speed , but its pretty fast.


You just need to increase your animation duration, currently at 10ms, like this:

$(window).scroll(function () {
  var top = ($(window).height() - $('.myPopUp').height()) / 2 + $(window).scrollTop();
  $('.myPopUp').animate({ top: top }, 200);
});

Animation frames are on a 13ms interval, so 10ms will be an instant change, giving it a longer duration, like the 200ms above will give it a much smoother effect. For quick scrolling scenarios, you'll probably want a .stop() in there too, like this:

$('.myPopUp').stop(true).animate({ top: top }, 200);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜