JQuery window scrolling event?

前端 未结 3 1488
清歌不尽
清歌不尽 2020-12-13 23:28

I have an ad in my header and a fixed ad at the bottom of my page that is always there. I want the fixed ad to appear only if the user has scrolled under the header ad. I lo

3条回答
  •  太阳男子
    2020-12-14 00:28

    See jQuery.scroll(). You can bind this to the window element to get your desired event hook.

    On scroll, then simply check your scroll position:

    $(window).scroll(function() {
      var scrollTop = $(window).scrollTop();
      if ( scrollTop > $(headerElem).offset().top ) { 
        // display add
      }
    });
    

提交回复
热议问题