如何使用jQuery隐藏div,然后在文档滚动条上使其淡入淡出? [英] How to use jQuery to hide div then fade it in on document scroll?
问题描述
我正在尝试使用jQuery在页面加载时隐藏div,但是当您向下滚动到某个点时它将消失.现在下面的脚本几乎可以做到这一点,我遇到的问题是div最初在页面加载时可见,我想将其隐藏...我似乎无法弄清楚该怎么做.
I'm trying to use jQuery to hide a div when the page loads, but when you scroll down to a certain point it will fade in. Right now the below script will do almost that, the problem I'm having is that the div is visible at first on page load, I want to hide it... I can't seem to figure out how.
$(window).bind("scroll", function() {
if ($(this).scrollTop() > 180) {
$("#magrig").fadeIn('slow');
}
else {
$("#magrig").stop().fadeOut('fast');
}
});
我尝试将.hide()添加到脚本中,但是我不知道如何重新格式化它.
I've tried adding .hide() into the script, but I can't figure out how to reformat it.
我原来是从这里得到的:滚动后淡入div
I got it origonally from here: Fade in div after scrolling
任何帮助将不胜感激!
推荐答案
仅使用普通的旧CSS,如何将其隐藏在pageload上:
How about just using plain old CSS, that will hide it on pageload :
#magrig {display:none}
这篇关于如何使用jQuery隐藏div,然后在文档滚动条上使其淡入淡出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!