I have used a scrollTop
function in jQuery for navigating to top, but strangely 'the smooth animated scroll' stopped working in Safari and Chrome (scrolling without smooth animation) after I made some changes.
But it is still working smoothly in Firefox. What could be wrong?
Here is the jQuery function I used,
jQuery:
$('a#gotop').click(function() {
$("html").animate({ scrollTop: 0 }, "slow");
//alert('Animation complete.');
//return false;
});
HTML
<a id="gotop" href="#">Go Top </a>
CSS
#gotop {
cursor: pointer;
position: relative;
float: right;
right: 20px;
/*top:0px;*/
}
I use:
because read jQuery scrollTop not working in Chrome but working in Firefox
This CSS conflict with scroll to top so take care of this
A better way to solve this problem is to use a function like this:
This will work across all browsers and prevents FireFox from scrolling up twice (which is what happens if you use the accepted answer -
$("html,body").animate({ scrollTop: 0 }, "slow");
).BUT, best approach is to scroll an id into your viewport using just native api (since you scroll to top anyway this can be just your outer div):
I don't think the scrollTop is a valid property. If you want to animate scrolling, try the scrollTo plugin for jquery
http://plugins.jquery.com/project/ScrollTo
Try using
$("html,body").animate({ scrollTop: 0 }, "slow");
This works for me in chrome.