简体   繁体   English

显示在Scroll上但不在页面加载上的Div

[英]Div that appears on Scroll but not on page load

I'm making this web page and I want a div to appear only on scrolling down 300px from the top of the page. 我正在制作此网页,并且我希望div仅在从页面顶部向下滚动300px时出现。 This is the JavaScript i borrowed from the net: 这是我从网上借来的JavaScript:

<script type="text/javascript">
$(document).ready(function(){
$(window).scroll(function(){
var y = $(window).scrollTop();
if(y > 300){
  $("#topdiv").fadeIn("slow");
 } else {
  $("#topdiv").fadeOut("fast");
}})});</script>

The only issue with this is that when the page loads, the div appears on top and then disappears once the user starts scrolling. 唯一的问题是,在页面加载时,div出现在顶部,然后在用户开始滚动时消失。 I dont want the div to appear once the page loads. 页面加载后,我不希望div出现。 Something like this is exactly what i want: 这样的事情正是我想要的:

http://www.calmdigital.com/ http://www.calmdigital.com/

Would greatly appreciate help! 将不胜感激帮助!

on document ready hide the div 准备好文档后隐藏div

$(function(){
if($("#topdiv").length>0)
 $("#topdiv").hide();
});

or hide it via css 或通过CSS隐藏它

#topdiv{
 display:none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM