using to scroll a single page website

前端 未结 2 518
后悔当初
后悔当初 2021-02-11 04:25

I am working on a single page website and have a problem with the tags.

I would like when the user clicks a Div they get taken to a diff

2条回答
  •  囚心锁ツ
    2021-02-11 04:54

    you can try something like this:

    $('a').click(function(e) {
       e.preventDefault();
       var scr = $('#target').offset().top; // top offset of the target element
        $('html, body').animate({scrollTop: scr}, 1000)
    })
    

    DEMO

提交回复
热议问题