Fire event when div is visible to visitor with jQuery?

前端 未结 4 1010
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 04:08

The function: I want to change the class of a certain item when a user see a certain div (scrolls down to it).

How I do it now: I\'

4条回答
  •  春和景丽
    2021-01-01 04:28

    I use a similar plugin but this uses the bind method and uses an event -> http://remysharp.com/2009/01/26/element-in-view-event-plugin/

    Sample usage :

    $('div').bind('inview', function (event, visible) {
      if (visible == true) {
        // element is now visible in the viewport
      } else {
        // element has gone out of viewport
      }
    });
    

提交回复
热议问题