简体   繁体   中英

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. 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();' or select 'html, body' for the scroll but none worked

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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