Skip to content

Instantly share code, notes, and snippets.

@dotZak
Last active August 29, 2015 14:28
Show Gist options
  • Save dotZak/26b74007438c9ee753e0 to your computer and use it in GitHub Desktop.
Save dotZak/26b74007438c9ee753e0 to your computer and use it in GitHub Desktop.
scroll events based on an interval
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