Jquery / Javascript find first visible element after scroll

后端 未结 3 1836
余生分开走
余生分开走 2020-12-06 10:54

I have code like below:

blah blah
blah blah 2&
3条回答
  •  臣服心动
    2020-12-06 11:36

    Here is one more idea, based on built-in javascipt functions.

    var range = document.caretRangeFromPoint(0,0); // screen coordinates of upper-left corner of a scolled area (in this case screen itself)
    var element = range.startContainer.parentNode; // this an upper onscreen element
    

    This bit of code is not a ready-to-use product — it's just an example, that works only in webkit browsers. If you want to use it, you should google for cross-browser equivalents of caretRangeFromPoint()

提交回复
热议问题