Skip to content

Instantly share code, notes, and snippets.

@daviferreira
Created March 31, 2012 23:46
Show Gist options
  • Save daviferreira/2269793 to your computer and use it in GitHub Desktop.
Save daviferreira/2269793 to your computer and use it in GitHub Desktop.
Smooth scrolling for anchor '#' links using jQuery and CoffeeScript
# based on http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery
$ ->
$('a[href^="#"]').on 'click.smoothscroll', (e) ->
e.preventDefault()
target = @hash
$target = $(target)
$('html, body').stop().animate {
'scrollTop': $target.offset().top
}, 500, 'swing', ->
window.location.hash = target
@teamgonuts
Copy link

Works great! Thanks

@kry8vmedia
Copy link

Thanks!

@Biaggio74
Copy link

Works fine, simple and easy ;) Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment