Skip to content

Instantly share code, notes, and snippets.

@luisfelipe-dev
Created November 9, 2016 12:02
Show Gist options
  • Select an option

  • Save luisfelipe-dev/54df8a50f5f192adc9f9e5eeefa8541b to your computer and use it in GitHub Desktop.

Select an option

Save luisfelipe-dev/54df8a50f5f192adc9f9e5eeefa8541b to your computer and use it in GitHub Desktop.
$('a[href*=#]').each(function () {
if (filterPath(location.pathname) == filterPath(this.pathname)
&& location.hostname == this.hostname
&& this.hash.replace(/#/, '')) {
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) + ']');
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false;
if ($target) {
var targetOffset = $target.offset().top;
$(this).click(function () {
if($(window).width() > 200){
$('html, body').animate({scrollTop: targetOffset}, 300);
return false;
}
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment