Skip to content

Instantly share code, notes, and snippets.

@mcbrwr
Created April 24, 2014 06:51
Show Gist options
  • Save mcbrwr/11244124 to your computer and use it in GitHub Desktop.
Save mcbrwr/11244124 to your computer and use it in GitHub Desktop.
Smooth scroll
$("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