How to find the closest element to the current position with jQuery

前端 未结 2 643
隐瞒了意图╮
隐瞒了意图╮ 2020-12-09 05:09

I have a document with several sections like this:

lalala lalala lalala
2条回答
  •  萌比男神i
    2020-12-09 05:54

    You can use $(window).scrollTop() and $(el).postion().top to figure out how far the element is from the top of the screen after scrolling.

    You can then use this information to manipulate the element as desired.

    Here is a working jsfiddle example: http://jsfiddle.net/gizmovation/x8FDU/

提交回复
热议问题