Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Jquary navbar change when section (DIV) is view-able in window Reply To: Jquary navbar change when section (DIV) is view-able in window

#267989
Shikkediel
Participant

Could you maybe add the HTML and relevant CSS as well so the code is fully working? That way I might be able to figure out why the coordinates are off. It should normally work as expected…

Although jQuery is also JavaScript, it has its own methods that can’t be directly used back and forth on the elements. The correct way to write the syntax for getBoundingClientRect while using it on a JQuery object is like this:

var top1 = $('.header')[0].getBoundingClientRect().top;

Where $('.header')[0] replaces element.