Skip to content

Instantly share code, notes, and snippets.

@ericjames
Created November 6, 2016 19:06
Show Gist options
  • Save ericjames/b4fd134c84f0326d53a5bb685480fd13 to your computer and use it in GitHub Desktop.
Save ericjames/b4fd134c84f0326d53a5bb685480fd13 to your computer and use it in GitHub Desktop.
jQuery scrollto article on page
$.fn.scrollTo = function(ele) {
$(this).animate({
scrollTop: $(ele).position().top
}, 1000);
};
$('.scrollto').click(function(e) {
e.preventDefault();
var target = $(this).attr('href');
var scrollpx = $(target).offset().top;
$('html, body').animate({
scrollTop: scrollpx
}, 1000);
if ($(window).width() <= 737 && $(this).attr('data-postnav')) {
$('.toggle-mobile-nav').click();
$('body').css({
'overflow': 'scroll'
});
}
if ($(this).attr('data-fireonce')) {
$(this).css({
'opacity': 0
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment