JQuery 窗口滚动事件? [英] JQuery window scrolling event?

查看:21
本文介绍了JQuery 窗口滚动事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页眉中有一个广告,我的页面底部有一个固定广告,该广告始终存在.我希望固定广告仅在用户滚动到标题广告下方时出现.我查看了 JQuery 文档,但我不确定我应该使用什么.

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 looked into the JQuery documentation, but I'm not really sure what I should use.

推荐答案

试试这个:http://jsbin.com/axaler/3/编辑

$(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();
    }
  });
});

这篇关于JQuery 窗口滚动事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆