Jump to content

Method with lesser resource usage then scrolltop


horst
 Share

Recommended Posts

Hi all,

I'm searching for a better solution on a problem with permanent monitoring positions of page elements when scrolling.

I have a table with table header, where a copy of it in a fixed header should popup when the original header is out of the viewport. That works very nice with one table and one fixed header. But there are also pages with multiple of those objects, and I don't want to check for each table, if it is currently within the viewport, but its header out of it.

A much better aprouch would be, if I could check which object is currently at top of the viewport. But I haven't found any examples on the web. Maybe I used the wrong keywords for searching, but everytime I found something, it only was checking the scrolltop position of an object. I want to check at vertical position 0 or 100 of the viewport what object is there currently positioned. All my tables have IDs.

Does anybody has a hint or tip for me?

Link to comment
Share on other sites

Hi,

uhm, actually I don't believe there is much to improve regarding the aspect of "many tables":

Quote

A much better aprouch would be, if I could check which object is currently at top of the viewport.

To check if an object is currently at the top - the computer has to iterate over the many candidates sooner or later anyway? :huh:
Could somebody comment on this so I can check whether my logic is faulty ;P

Yet what certainly can be improved:

highly recommended: debouncing / throttling:  https://davidwalsh.name/javascript-debounce-function if you don't know about that already.
... and of course the actual calculation of the distances can be improved ... but I don't have something fancy at hand right now ... but I enjoy looking at code and think about what could be improved ;)

 

  • Like 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...