pantofka pantofka - 4 months ago 19
Javascript Question

Redirect to other html page and scrollTop: to a certain div

It's been already asked, but the two given answers don't work for me.
Redirect to some other page then animate to reach a certain scrollTop
My html is something like:

html1:

<!doctype html>
<html clalang="en">
<head>

</head>
<body>
<a href="index.html" id="boxes">boxes</a>
</body>
</html>


html2:

<!doctype html>
<html clalang="en">
<head>

</head>
<body>
<div id="goto"></div>
</body>
</html>


So I need when you click on in html1 to go to in html2

Thank you for the help !

Answer

That's what a url hash is for:

<a href="index.html#goto" id="boxes">boxes</a>

Browser will automatically scroll to the matching id

Comments