最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - A jQuery scrollTop(); with Transition - Stack Overflow

programmeradmin0浏览0评论

I can't figure out of to make scroll, (when a div is clicked), and make it smooth. (like not going straight to the scroll position)

Here's my code:

$('.about-center').click(function() {
    var div = document.getElementById('ABOUT');
    var pos = div.offsetTop;
    
    $(window).scrollTop(pos);
});

I can't figure out of to make scroll, (when a div is clicked), and make it smooth. (like not going straight to the scroll position)

Here's my code:

$('.about-center').click(function() {
    var div = document.getElementById('ABOUT');
    var pos = div.offsetTop;
    
    $(window).scrollTop(pos);
});
Share Improve this question edited Dec 16, 2020 at 0:15 peterh 1 asked Sep 6, 2014 at 17:06 Alex SafayanAlex Safayan 3,0634 gold badges19 silver badges22 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

try this one:

$('.about-center').click(function() {
    var div = $('#ABOUT');
    var pos = div.offset().top;

    $('html, body').animate({scrollTop:pos},2000); // will take two seconds to scroll to the element
});
发布评论

评论列表(0)

  1. 暂无评论