/ Published in: Other
Expand |
Embed | Plain Text
$(document).ready(function() { $('.backtotop').click(function(){ $('html, body').animate({scrollTop:0}, 'slow'); }); });
Comments
Subscribe to comments
You need to login to post a comment.

thanks !!
I does not seem to work in IE
I added a return false at the end of it, so if the class is applied to a block level element that contains anchor in it, it won't try to first follow the anchor then animate, which was causing a jitter for me in Firefox.
$(document).ready(function() { $('.backtotop').click(function(){ $('html, body').animate({scrollTop:0}, 'slow'); return false; }); });
Could not get this to work on my site.
I created a .js file. Referenced the my sites head, but the link would not 'scroll up'.
Help?
Works like a charm, thanks! I just re-used the line 3 in my context and that's working perfect!
Thanks man, really worked. @DraStudio : the 'return false' in the end is the magic for everything works perfectly.
Nice man!!!
Oh dear, just awesome. :D
Great snippet to keep in the arsenal, I was trying to get a similar function to work on a paged form and going about it way more complex with adverse results, this was perfect to add to my .click action!
Hi all, what about if I need to scroll to top -or to other div“s wherever they were- from diferents elements...?
The example shows the way to do that from only one element (".backtotop") Im handling diferents functions from diferent elements, including one swf file ;) But I doesnt works if I try to trigger one function from diferents elements :(
Cheers!
you can also use a preventdefault
$(document).ready(function() { $('.backtotop').click(function(e){ $('html, body').animate({scrollTop:0}, 'slow'); e.preventDefault(); }); });
Nice.. works like a charm :) with: returne false..
Perfect, thanks.