Skip to content

Instantly share code, notes, and snippets.

@shehabkhan013
Created December 17, 2017 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shehabkhan013/697605bcca3c2b14044af95338b5b265 to your computer and use it in GitHub Desktop.
Save shehabkhan013/697605bcca3c2b14044af95338b5b265 to your computer and use it in GitHub Desktop.
function scrollToTop($topClass){
var top_0 = {scrollTop:0};
var topClass = $($topClass);
topClass.on("click" , function(e){
$("html,body").animate(top_0,1000);
return false;
});
$(window).scroll(function(){
if($(this).scrollTop() > 400) {
topClass.fadeIn(500);
}
else {
topClass.fadeOut(500);
}
});
}
scrollToTop('.scrolltotop i');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment