Trigger event when user scroll to specific element - with jQuery

后端 未结 12 1365
攒了一身酷
攒了一身酷 2020-11-22 11:52

I have an h1 that is far down a page..

TRIGGER EVENT WHEN SCROLLED TO.

and I want to trigger an alert

12条回答
  •  太阳男子
    2020-11-22 12:50

    Inview library triggered event and works well with jquery 1.8 and higher! https://github.com/protonet/jquery.inview

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

    Read this https://remysharp.com/2009/01/26/element-in-view-event-plugin

提交回复
热议问题