Skip to content

Instantly share code, notes, and snippets.

@cesarkohl
Created October 3, 2015 21:54
Show Gist options
  • Select an option

  • Save cesarkohl/9b57833f6533c156c67c to your computer and use it in GitHub Desktop.

Select an option

Save cesarkohl/9b57833f6533c156c67c to your computer and use it in GitHub Desktop.
jQuery - Anchor section with fade
/**
* Anchor with fade
* Example: <a href="#example-1"/> <div id="example-2"/>
*/
$('a.scroll-smooth').on('click',function (e) {
e.preventDefault();
var target = this.hash;
var $target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 'slow', 'swing', function () {
window.location.hash = target;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment