Created
June 26, 2017 14:01
-
-
Save xorus/2265977a7cbfb1776357347c9a582876 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var sticky = document.getElementById('seo-top-sticky'); | |
var stickyOffset = sticky.getBoundingClientRect().top + document.body.scrollTop; | |
console.log(stickyOffset); | |
var titleShown = false; | |
var onScroll = function () { | |
if (stickyOffset < (window.pageYOffset || document.scrollTop) - (document.clientTop || 0)) { | |
if (!titleShown) { | |
console.log("on"); | |
$(sticky).addClass('on'); | |
titleShown = true; | |
} | |
} else { | |
if (titleShown) { | |
$(sticky).removeClass('on'); | |
titleShown = false; | |
} | |
} | |
}; | |
window.addEventListener('scroll', function () { | |
onScroll(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment