Reputation: 2823
So I have a simple piece of Javascript that sticks a header on scroll past
<div id="left">hello world</div>
$(document).ready(function () {
$(window).scroll(stickyRelocate);
});
var left = document.getElementById("left");
var stop = (left.offsetTop - 60);
window.onscroll = function (e) {
var scrollTop = (window.pageYOffset !== undefined) ? window.pageYOffset : (document.documentElement || document.body.parentNode || document.body).scrollTop;
console.log(scrollTop, left.offsetTop);
if (scrollTop >= stop) {
left.className = 'stick';
} else {
left.className = '';
}
}
I need to build a new class
<div="remove-stick"></div>
And have the sticky removed after scroll past.
Any help is much appreciated.
Upvotes: 0
Views: 411