Skip to content

Instantly share code, notes, and snippets.

@xorus
Created June 26, 2017 14:01
Show Gist options
  • Save xorus/2265977a7cbfb1776357347c9a582876 to your computer and use it in GitHub Desktop.
Save xorus/2265977a7cbfb1776357347c9a582876 to your computer and use it in GitHub Desktop.
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