2017-04-26 39 views
0

我有一个顶部有100vh div的主页,我想在此div之后向下滚动时隐藏它。或者在滚动这个100vh div后禁用向上滚动的可能性。当你到达网站时,这个div应该只出现一次。滚动100vh之后的滚动滚动顶部

这里的链接:http://tmp.thomasdesnoyers.com/ 经过大彩色背景div你shloudn't能够向上滚动。

我尝试添加“显示:无”滚动窗口的高度后proprety到这个div但它把所有的内容... 如果有人对此有任何线索的作用...

这股利来隐藏:

<div id="home-background" class="monobg"> 


<?php $images_toomany = array("/wp-content/img/toomany.svg", "/wp- 
content/img/toomany_2.svg", "/wp-content/img/toomany_3.svg", "/wp- 
content/img/toomany_4.svg", "/wp-content/img/toomany_5.svg");?> 
<?php echo '<img src="'.$images_toomany[array_rand($images_toomany)].'" 
class="toomany" />';?> 

<?php $images_pictures = array("/wp-content/img/pictures.svg", "/wp- 
content/img/pictures_2.svg", "/wp-content/img/pictures_3.svg", "/wp- 
content/img/pictures_4.svg", "/wp-content/img/pictures_5.svg",);?> 
<?php echo '<img src="'.$images_pictures[array_rand($images_pictures)].'" 
class="pictures" />';?> 


</div> 

谢谢。

Thomas

+0

请发表您的代码,感谢 – sol

+0

*“(为什么不是这个代码工作“?)求调试帮助问题”必须包括所期望的行为,一个特定的问题或错误**和在问题本身中重现它所需的最短代码**。没有明确问题陈述的问题对其他读者无用“* - [我可以询问什么主题关于堆栈溢出?](https:// stackoverflow .com/help/on-topic) – Santi

+0

只需使用div的代码编辑我的帖子即可隐藏 – tomdes

回答

0

是的。超级简单。当您想要防止滚动到当前视口之外时,只需将overflow:hidden添加到您的body元素。你可以通过JS或jQuery动态地做到这一点。

+0

它允许通过箭头键进行滚动,例如。 – NikxDa

+0

不知道我跟着你。溢出:隐藏在身体上将防止通过键盘和鼠标滚动。 – Korgrue

+1

感谢您的回答。 只需将其添加到身体,它会做相反的事情。它只显示我想要隐藏并隐藏页面其余部分的主页背景div。 – tomdes

0

试试这个

$(window).scroll(function() { 

    var div_height = $('#home-background').height();  
    var page_scroll = $(window).scrollTop(); 

    if(page_scroll > div_height) { 
     $('#home-background').css('display', 'none'); 
    } 
}); 
+0

谢谢你的答案。 这个技术的唯一问题是它把所有的内容都拿出来,因为顶部的大div不再存在。 – tomdes

0

这里我用溢出TECHNIC代码。 我认为这是一个良好的开端:

jQuery(function($) { 

var $nav = $('body'); 
var $win = $(window); 
var winH = $win.height(); // Get the window height. 

$win.on("scroll", function() { 
    if ($(this).scrollTop() > winH) { 
     $nav.addClass("hide"); 
    } 
}).on("resize", function(){ // If the user resizes the window 
    winH = $(this).height(); // you'll need the new height value 
}); 

});