当发生一定量的滚动时隐藏元素 [英] Hide an element when a certain amount of scrolling has occured

查看:15
本文介绍了当发生一定量的滚动时隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想在滚动 N 个像素后隐藏页面上的元素.

I'd just like to hide an element on my page, after N number of pixels have been scrolled.

$(window).scroll(function(){
  if($(document).scrollTop() > 200){
    $('.fixedelement').css({'display': 'none'});
  }
});

我认为这可能会奏效,滚动 200 像素后 .fixedelement 会消失.唉,它不起作用.有什么想法吗?

I thought this might work, and after 200px of scrolling the .fixedelement would vanish. Alas, it doesn't work. Any thoughts?

推荐答案

这里似乎工作正常:http://jsfiddle.net/maniator/yDVXY/

$(window).scroll(function() {
    if ($(this).scrollTop() > 200) { //use `this`, not `document`
        $('.fixedelement').css({
            'display': 'none'
        });
    }
});

这篇关于当发生一定量的滚动时隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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