Skip to content

Instantly share code, notes, and snippets.

Created June 21, 2022 11:29
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(){
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