Skip to content

Instantly share code, notes, and snippets.

@apsolut
Last active October 6, 2016 12:58
Show Gist options
  • Save apsolut/0ce01b9bbab02e10a161d99abbfec2cc to your computer and use it in GitHub Desktop.
Save apsolut/0ce01b9bbab02e10a161d99abbfec2cc to your computer and use it in GitHub Desktop.
onepage website with working url-s
jQuery(document).ready(function () {
var clickHandler = ('ontouchstart' in document.documentElement ? "touchstart" : "click");
jQuery("#menu-mainmenu li a:not(.ignore)").bind(clickHandler, function(e) {
// link - substring will take only "#name" - and you can add link with "/#name"
// so it can work on onepage site that have blog.
var link = jQuery(this).attr('href').substring(jQuery(this).attr('href').indexOf('#'))
// this will take link and calculate top offset
var posi = jQuery(link).offset().top;
// use GreenSock (GSAP) for animations - TweenLite
// this will scroll window to posi location
TweenLite.to(window, 1.5, {scrollTo: {y: posi -80}, ease: Power3.easeOut});
e.preventDefault();
});
}); //JQREADY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment