I am having a url e.g. www.website.com/#divIdToScrollTo
Problem:
what I want here is on page load, the id following # will be extracted[which has already been mentioned as id of target div.]. And when the page is fully loaded the page should first stay at top and then smoothly start scrolling towards the div with a duration of say 5 seconds.
Current approach:
var elem = $('#_' + window.location.hash.replace('#', ''));
if(elem) {
$('html, body').animate({
scrollTop: $( elem ).offset().top
}, 5000);
}
My current solution extracts the id from the url and on page load is directly present at the target div. I am unable to see any smooth scrolling.
So, can I achieve the smooth scrolling I am looking for here. Please share your thoughts.[WITH CODE]