javascript - Scroll offset changing menu item class -
i have page in magento categories , products listed. on top have menu categories , items scroll must class can change color.
i have script @ moment:
function onscroll(event){ var scrollpos = $(document).scrolltop(); $('ul.nf-category-menu li a').each(function () { var currlink = $(this); var refelement = $(currlink.attr("href")); if (refelement.position().top <= scrollpos && refelement.position().top + refelement.height() > scrollpos) { $('ul.nf-category-menu li a').removeclass("active"); currlink.addclass("active"); } else{ currlink.removeclass("active"); } }); } but class changing div div soon, can give offset class added later?
update:
it's no changing "active" class when te title 150px away top, change class around 80px top.
regards,
i fixed it, quite simple after trying things. how done:
function onscroll(event){ var scrollpos = $(document).scrolltop(); $('ul.nf-category-menu li a').each(function () { var currlink = $(this); var refelement = $(currlink.attr("href")); if (refelement.position().top+243 <= scrollpos && refelement.position().top + refelement.height() > scrollpos) { $('ul.nf-category-menu li a').removeclass("active"); currlink.addclass("active"); } else{ currlink.removeclass("active"); } }); } if (refelement.position().top had changed to: if (refelement.position().top+243 243 amount of pixels of offset.

Comments
Post a Comment