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.

enter image description here

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

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -