Skip to content

Instantly share code, notes, and snippets.

@0xMALVEE
Created September 21, 2018 15:13
Show Gist options
  • Save 0xMALVEE/259ff324db9cad09298c007703b154f2 to your computer and use it in GitHub Desktop.
Save 0xMALVEE/259ff324db9cad09298c007703b154f2 to your computer and use it in GitHub Desktop.
Smooth Scrolling
(function(a,c){var b=(function(){var d=c(a.documentElement),f=c(a.body),e;if(d.scrollTop()){return d}else{e=f.scrollTop();if(f.scrollTop(e+1).scrollTop()==e){return d}else{return f.scrollTop(e)}}}());c.fn.smoothScroll=function(d){d=~~d||400;return this.find('a[href*="#"]').click(function(f){var g=this.hash,e=c(g);if(location.pathname.replace(/^\//,'')===this.pathname.replace(/^\//,'')&&location.hostname===this.hostname){if(e.length){f.preventDefault();b.stop().animate({scrollTop:e.offset().top},d,function(){location.hash=g})}}}).end()}}(document,jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment