简体   繁体   English

jQuery-在scrollTop()之后页面跳回到上一个位置

[英]JQuery - Page jumps back to previous position after scrollTop()

so I want my page to start at the bottom which I try to achieve with this bit: 所以我希望页面从底部开始,我尝试通过以下方式实现:

$(document).ready(function() {
  $('body').scrollTop($(document).height()-$(window).height());
})

Now it does what it's supposed to for about 0.5 seconds and then it jumps back to my previous scroll position. 现在,它执行了预期的操作约0.5秒钟,然后又跳回到我以前的滚动位置。 I've noticed that it jumps after fully loading the background image. 我注意到,它在完全加载背景图像后会跳转。 I have tried several solutions from similar questions like add 'return false;', call 'preventDefault();' 我已经尝试过类似问题的几种解决方案,例如添加'return false;',调用'preventDefault();'。 or select 'html, body' for the scroll but none worked 或为滚动选择“ html,body”,但没有用

any of you have a solution to my problem? 你们有解决我问题的办法吗?

Why not just this: I tried it in a page with a div 1000px high and filled with garbage tex, it scrolled to the bottom just fine and never jumped back: 为什么不这样:我在一个div高1000px并充满垃圾tex的页面中尝试了它,它滚动到底部就好了,并且从不跳回去:

window.scrollTo ( 0, document.body.scrollHeight );

The only way this could fail as far as I can see is if something triggers "ready" again, in which case maybe just do the usual "body onload="scrollBottom()" sort of thing. 就我所知,这可能会失败的唯一方法是,是否再次触发“就绪”,在这种情况下,可能只是执行通常的“ body onload =“ scrollBottom()”之类的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM