Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
adds class 'stuck' to elements that are stuck. Uses Bootstraps' `position-sticky` class as a selector.
const stickes = document.body.querySelectorAll('.position-sticky');
window.addEventListener('scroll', function(){
stickes.forEach(function(el){
el.classList.toggle('stuck', el.getBoundingClientRect().top === parseInt(window.getComputedStyle(el).top, 10));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment