Skip to content

Instantly share code, notes, and snippets.

Last active June 23, 2023 13:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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(){
let stuck = false;
const rect = el.getBoundingClientRect();
if (window.getComputedStyle(el).bottom == 'auto') {
stuck = === parseInt(window.getComputedStyle(el).top, 10);
} else if (window.getComputedStyle(el).top == 'auto') {
stuck = rect.height + < window.innerHeight;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment