How to determine when an HTML5 element has been viewed?

前端 未结 4 1714
小鲜肉
小鲜肉 2020-12-10 09:21

I am wondering if there are any HTML5 events associated with whether or not an element has been viewed or \"scrolled into view\" by the user.

An example could be a l

4条回答
  •  不知归路
    2020-12-10 09:50

    I had to do something similar to this when I built http://f1circle.com.
    When the bottom banner becomes visible, I have to show a spotlight to the user asking him to login.

    The code that achieves it using angularjs can be viewed at https://github.com/rajegannathan/angularUtilities/blob/master/directives/eagerload.js

    Though it is an angularjs directive, the main logic is in plain javascript. Basically I check if the the last feed's bottom edge is visible and then trigger the spotlight.

    I can explain more if required.

提交回复
热议问题