I have 3 anchors on the page. I want to highlight a list of buttons that are fixed depending on which anchor is closest to the middle of the viewport.
How would I do this?
I'm already using the InView and ViewportOffset plugins.
I have 3 anchors on the page. I want to highlight a list of buttons that are fixed depending on which anchor is closest to the middle of the viewport.
How would I do this?
I'm already using the InView and ViewportOffset plugins.
so if you do no the viewport's coordinates, then, you can get the middle:
now you do something like:
now you have the "square" of the distances in the array, you need to search for the smallest (closest to the middle):
now you have the index of the closest element in "closest" so you can do anything with it like: