I have this code that when you open a link it will scroll to the specific div on that page.
collection.html
<a id='about' href="index.html">about</a>
index.html
<div id='#moreInfo>contents here</div>
<script>
$(document).ready(function(){
$('html, body').animate({
scrollTop: $("#moreInfo").offset().top
}, 1000);
})
</script>
My problem is whenever I load the index.html, it always scrolls to the moreInfo div. What I want is when I'm on collection.html and I click on the about link, it will redirect to index.html then scroll smoothly to the moreInfo div.
I'll appreciate any answer.
You can do this by setting a GET parameter on the link URL then reading that parameter when the next page loads:
collection.html
index.html
An easy way to do this is just to have your link point to a location hash.
Then, in your JavaScript you could just check if the person came from that link.
You can achieve smooth scrolling using html only
your page contains div like
You have to scroll to this div using
and simply use below code in your css