开发者

How to smooth scrolling using jquery

开发者 https://www.devze.com 2023-03-29 23:19 出处:网络
I am using scrollTop to scroll through content div using this v开发者_开发百科ar container = $(\'#content\');

I am using scrollTop to scroll through content div using this

    v开发者_开发百科ar container = $('#content');
    container.scrollTop(
        $('#topic-' + id).offset().top - container.offset().top
    );

    container.scrollTop(
        container.scrollTop() + $('#topic-' + id).offset().top - container.offset().top
    );

It works. But the scrolling is hard on the eyes. Is there any way to ease the transistion.

I appreciate any help.


From the jquery API ...

You need to use the scrolltop as a method in the animation. i.e. :

.animate({scrollTop:0}, 2000, 'ease')
0

精彩评论

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