using to scroll a single page website

前端 未结 2 517
后悔当初
后悔当初 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

    0 讨论(0)
  • 2021-02-11 04:57

    Instead of trying to manipulate how the DOM elements work, wouldn't it be much easier to change your jQuery selector? http://api.jquery.com/parent-selector/

    0 讨论(0)
提交回复
热议问题