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

javascript - Why scroll to top not working when I use jQuery? - Stack Overflow

programmeradmin0浏览0评论

I have a popup that is dynamically loading content and using overflow: auto to maintain the popup size and in turn make it scrollable. I have a link at the bottom currently using anchors to scroll to the top of the div. Unfortunately it is also forcing the page to scroll down to that point as well as scroll to the top of that div.

I am trying to prevent the page from scrolling and only scroll to the top of the div. I have tried numerous scenarios of scroll to top:

$('#id').scrollTop(0);

as well as

$('#id').animate({
   scrollTop: 0
}, 'slow');

Unfortunately this is doing nothing. I am not getting any errors. I have attempted to try it in a console and not attached to any click event and it does nothing and just prints the id to the console that I am targeting.

Here is the link to the actual production version of this page. If you click the link for privacy policy, terms or learn more and then hit any of the back to top links you will see what the issue is.

Here is the site

I have a popup that is dynamically loading content and using overflow: auto to maintain the popup size and in turn make it scrollable. I have a link at the bottom currently using anchors to scroll to the top of the div. Unfortunately it is also forcing the page to scroll down to that point as well as scroll to the top of that div.

I am trying to prevent the page from scrolling and only scroll to the top of the div. I have tried numerous scenarios of scroll to top:

$('#id').scrollTop(0);

as well as

$('#id').animate({
   scrollTop: 0
}, 'slow');

Unfortunately this is doing nothing. I am not getting any errors. I have attempted to try it in a console and not attached to any click event and it does nothing and just prints the id to the console that I am targeting.

Here is the link to the actual production version of this page. If you click the link for privacy policy, terms or learn more and then hit any of the back to top links you will see what the issue is.

Here is the site

Share Improve this question edited Mar 12, 2021 at 23:39 Amir 1,3583 gold badges15 silver badges29 bronze badges asked Dec 18, 2013 at 15:38 user2112618user2112618 3466 silver badges21 bronze badges 3
  • Can you please explain a little better what are you trying to do? Site and functionality looks good to me. – Babblo Commented Dec 18, 2013 at 15:42
  • Your production site is at a vw. sub-domain? – Jasper Commented Dec 18, 2013 at 15:43
  • BTW, if I fix the problem I don't want the points, just a VW Phaeton :) – Babblo Commented Dec 18, 2013 at 15:47
Add a ment  | 

1 Answer 1

Reset to default 5

i used

$( 'html, body' ).animate( { scrollTop: 0 }, 0 );
发布评论

评论列表(0)

  1. 暂无评论