Last active
August 29, 2015 14:28
-
-
Save dotZak/26b74007438c9ee753e0 to your computer and use it in GitHub Desktop.
scroll events based on an interval
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
if (document.getElementById('widget-slide-dock')) | |
{ | |
var didScroll = false | |
, randomPost = document.getElementById('widget-slide-dock') | |
, triggerElement = document.getElementById('site-sidebar') | |
, targetPosition = (triggerElement.offsetHeight + jQuery(triggerElement).offset().top); | |
setInterval( function() | |
{ | |
if(didScroll) | |
{ | |
didScroll = false; | |
} | |
}, 100); | |
window.onresize = function() | |
{ | |
var targetPosition = (triggerElement.offsetHeight + jQuery(triggerElement).offset().top); | |
} | |
window.onscroll = function() | |
{ | |
didScroll = true; | |
if ( ((window.pageYOffset + window.innerHeight) - randomPost.offsetHeight) >= targetPosition ) | |
{ | |
randomPost.classList.add('slide-dock-on'); | |
} | |
else | |
{ | |
randomPost.classList.remove('slide-dock-on'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment