function createStickery(sticky) { if(sticky == null) { return; } const pos = sticky.offsetTop; window.addEventListener('scroll', () => { if(window.pageYOffset > pos) { sticky.classList.add('custom-sticky') else { sticky.classList.remove('custom-sticky'); } }); }
function createSticky(sticky) { if (typeof sticky == undefined) return; var pos = sticky.offsetTop, win = window; win.addEventListener("scroll", function() { win.scrollTop > pos ? sticky.classList.add("custom-sticky") : sticky.classList.remove("custom-sticky"); }); }
I'm glad seeing people asking how to move away from jQuery
Position: fixed?
if that concerns sticky nav // footer take a look at pures CSS implementation:
Обсуждают сегодня