Scroll To Top On Page Load (HTML)

2019-07-29 05:47发布

问题:

I have tried both onload="window.scrollTo(0,0);" and onload="$('html,body').scrollTop(0);" but after the page loads it still stays at the current position, I am using frames. I have tried some of the other suggestions but still no luck could someone please point me in the right direction. Do I need to add a scroll to top to my frame? I need the page that contains the frame to reload when the frame inside reloads, hope it makes sense.

<body onload="window.scrollTo(0,0); $('html,body').scrollTop(0);"> <iframe id="my-iframe-tag" scrolling="no"> </iframe> </body>

回答1:

Using the scrollTop method on DOM ready:

$(document).ready(function(){
    $(this).scrollTop(0);
});


回答2:

hi all this seems to have done the trick onload="parent.scrollTo(0,0);" after some searching this helped Scroll to top of parent frame on iframe change? thanks though



回答3:

Use below code To Scroll to top, you can create one button and on click event you need to fire this code.

$("html, body").animate({ scrollTop: 0 }, "slow");