Last active
August 29, 2015 14:27
-
-
Save kezabelle/1b44dcd42b3c4ded6a47 to your computer and use it in GitHub Desktop.
Hide, say, a navigation panel until the first "pane" has been scrolled over (eg: landing "section" is full page)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($window, $document, $, selector) { | |
var readyup = function () { | |
var previousScroll = 0; | |
var showNav = false; | |
var didScroll = false; | |
var windowHeight; | |
var documentHeight; | |
var $selector = $(selector); | |
if ($selector.length < 1) { | |
return false; | |
} | |
var doHeightCalculation = function() { | |
windowHeight = parseInt($($window).height()); | |
documentHeight = parseInt($($document).height()); | |
return [windowHeight, documentHeight]; | |
} | |
$($window).resize(doHeightCalculation); | |
doHeightCalculation(); | |
var doScrollCalculation = function () { | |
var currentScroll = parseInt($(this).scrollTop()); | |
showNav = currentScroll >= windowHeight; | |
didScroll = currentScroll !== previousScroll; | |
previousScroll = currentScroll; | |
return [showNav, didScroll]; | |
} | |
$($window).scroll(doScrollCalculation); | |
var doScrollWork = function() { | |
if (showNav === true) { | |
return $selector.addClass("delay-show"); | |
} else { | |
return $selector.removeClass("delay-show"); | |
} | |
} | |
setInterval(doScrollWork, 200); | |
return true; | |
} | |
return $($document).ready(readyup); | |
})(window, document, window.$, '[data-delay-show]'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment