JQuery window scrolling event?

前端 未结 3 1470
清歌不尽
清歌不尽 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:13

    Check if the user has scrolled past the header ad, then display the footer ad.

    if($(your header ad).position().top < 0) { $(your footer ad).show() }

    Am I correct at what you are looking for?

    0 讨论(0)
  • 2020-12-14 00:16

    Try this: http://jsbin.com/axaler/3/edit

    $(function(){
      $(window).scroll(function(){
        var aTop = $('.ad').height();
        if($(this).scrollTop()>=aTop){
            alert('header just passed.');
            // instead of alert you can use to show your ad
            // something like $('#footAd').slideup();
        }
      });
    });
    
    0 讨论(0)
  • 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
      }
    });
    
    0 讨论(0)
提交回复
热议问题