在发生一定量的滚动时隐藏元素 [英] Hide an element when a certain amount of scrolling has occured
本文介绍了在发生一定量的滚动时隐藏元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在滚动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'});
}
});
我认为这可能有效,并且在滚动200px后,.fixedelement将消失. las,这行不通.有什么想法吗?
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/
It seems to work fine here: http://jsfiddle.net/maniator/yDVXY/
$(window).scroll(function() {
if ($(this).scrollTop() > 200) { //use `this`, not `document`
$('.fixedelement').css({
'display': 'none'
});
}
});
这篇关于在发生一定量的滚动时隐藏元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文