Skip to content

Instantly share code, notes, and snippets.

@CydGoblin
Last active September 26, 2019 18:47
Show Gist options
  • Save CydGoblin/20f0c9553afc1015b1026c9337a2845f to your computer and use it in GitHub Desktop.
Save CydGoblin/20f0c9553afc1015b1026c9337a2845f to your computer and use it in GitHub Desktop.
Commonly used JS
(function($){
$.fn.scrollFixed = function(params){
params = $.extend( {appearAfterDiv: 0, hideBeforeDiv: 0}, params);
var element = $(this);
if(params.appearAfterDiv)
var distanceTop = element.offset().top + $(params.appearAfterDiv).outerHeight(true) + element.outerHeight(true);
else
var distanceTop = element.offset().top;
if(params.hideBeforeDiv)
var bottom = $(params.hideBeforeDiv).offset().top - element.outerHeight(true) - 10;
else
var bottom = 200000;
$(window).scroll(function(){
if( $(window).scrollTop() > distanceTop && $(window).scrollTop() < bottom )
element.addClass('scrolled');
else
element.removeClass('scrolled');
});
};
})(jQuery);
$(document).ready( function(){
$("nav.navbar").scrollFixed({appearAfterDiv:'.hero'});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment