Skip to content

Instantly share code, notes, and snippets.

@hadamlenz
Last active November 12, 2015 20:22
Show Gist options
  • Save hadamlenz/fd4ca87d41b21854ec70 to your computer and use it in GitHub Desktop.
Save hadamlenz/fd4ca87d41b21854ec70 to your computer and use it in GitHub Desktop.
//the function
jQuery.fn.paralaxical = function (speed){
var theOffset;
if($(this).hasClass('left-nav-fixed')){
var lastOffset = Number($(this).attr('data-last-offset-top'));
var negativespeed = speed*-1;
var thetop = $(this).position().top;
var thebottom = thetop + $(this).height();
if( $(this).height() + leftNavTopPosition > $(window).height() ){//yes the nav is larger than the page
if($(this).offset().top > lastOffset && thebottom > $(window).height()){//we are scrolling down
theOffset = negativespeed;
}else if($(this).offset().top < lastOffset && thetop < 67){//we are scrolling up
theOffset = speed;
}
}
}
$(this).offset({top: $(this).offset().top+theOffset});
$(this).attr('data-last-offset-top', $(this).offset().top);
};
//keep track of where the nav is in the world
$('.left-nav-wrapper').attr('data-last-offset-top', leftNavTopPosition);
//add the function to the scroll listener
$(window).on('scroll', function () {
$('.left-nav-wrapper').paralaxical(3);
}
//in toggleFixedLeftNav comment out the autoclose lines
//$('.nav-left-list').removeClass('leftnav-open'); // comment in order to prevent autoclose
//$('.nav-list-l1').removeClass('leftnav-submenu-open'); // comment in order to prevent autoclose
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment