undefined) return;
var pos = sticky.getBoundingClientRect().top;
window.addEventListener("scroll", function() {
this.pageYOffset > pos ? sticky.classList.add("custom-sticky") : sticky.classList.remove("custom-sticky");
});
}
Instead of using a single backstick, use three and create a block, it reads better
Code looks ok but you may want to debounce that scroll
typeof sticky will never be undefined it will be a string like 'undefined' or 'number' etc.
typeof sticky === 'undefined'
Btw, sticky can't be undefined, it will be either a DOM node or null, if (!sticky) is a better check
Обсуждают сегодня