jQuery - How to scroll an anchor to the top of the page when clicked?

前端 未结 3 502
栀梦
栀梦 2021-01-06 14:39

I have a list of links in div elements and I am using dropcontent.js to load content into another div when a link is clicked. I would now like to a

相关标签:
3条回答
  • 2021-01-06 15:05

    Not a direct answer to your question, but a good reference that you may want to use.

    http://demos.flesler.com/jquery/scrollTo/

    The jQuery scrollTo plugin lets you scroll to any anchor <a> in your page. If you just place an anchor on top of your window, you can use scrollTo to go there directly with an animation.

    0 讨论(0)
  • 2021-01-06 15:08

    Here is how you scroll the link to the top:

    $('.work a').click(function() {
         $('html,body').animate({scrollTop: $(this).offset().top}, 500);
    }); 
    
    0 讨论(0)
  • 2021-01-06 15:16

    This answered question linked below is closely related and good info for all people that like to be able to

    • scroll the page to a certain element, div id

    • have that element scroll to the the top of the page by clicking an anchor from that element

    • have that element scroll to the the top of the page by clicking the actual div id containing all the anchor links; "click catcher div"

    Scroll element to top of page by clicking anchor inside element or anywhere inside containing div id

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