I have an anchor link which links to another page. When it is clicked, by default it goes to the top of the next page. I want it brought to a certain position of the page. H
here is my solution.
$('.container').on('click', function(e){
var hash = $(this).find('a').attr('href'),
target = $('html').find('p'+hash),
location = target.offset().top;
$('html, body').stop().animate({scrollTop: location}, 1000);
e.preventDefault();
});
html would be like:
So when clicked on the anchor it will scroll to the respective anchor in the document.