Created
April 24, 2014 06:51
-
-
Save mcbrwr/11244124 to your computer and use it in GitHub Desktop.
Smooth scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("a[href*=#]:not([href=#])").click -> | |
if location.pathname.replace(/^\//, "") is @pathname.replace(/^\//, "") and location.hostname is @hostname | |
scrollByClick = true | |
target = $(@hash) | |
target = (if target.length then target else $("[name=" + @hash.slice(1) + "]")) | |
offset_fix = -60 | |
if $(window).scrollTop() < 10 | |
offset_fix = -200 | |
if target.length | |
$("html,body").animate | |
scrollTop: target.offset().top+offset_fix | |
, 1000, -> | |
scrollByClick = false | |
false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment