简体   繁体   English

如何用另一个div隐藏动画div

[英]how to hide animating div with another div

I am working on to make the gray box hidden once it's out of the red box. 我正在努力将灰色框从红色框移出后隐藏起来。 The parent that is going to be hidden is exactly the part that is out of the box. 将要隐藏的父级就是开箱即用的部分。 If half of the box is out, only half of the box becomes invisible. 如果框的一半已用完,则只有框的一半不可见。

 $( "#right" ).click(function() { $( ".block" ).animate({ "left": "+=50px" }, "slow" ); }); $( "#left" ).click(function(){ $( ".block" ).animate({ "left": "-=50px" }, "slow" ); }); 
  .block { position: absolute; background-color: #abc; left: 50px; width: 90px; height: 90px; margin: 5px; } .big_block { left: 100px; right: 100px; background-color: red; height: 100px; width: 100px; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="left">&laquo;</button> <button id="right">&raquo;</button> <div class="big_block"> <div class="block"></div> </div> 

adding z-index: 1 to big_block class has not helped coz it makes it completly on top 在big_block类中添加z-index:1并不能帮助它完全位于顶部

Add position:relative to big_block and use overflow:hidden 添加position:relative对于big_block并使用overflow:hidden

 $("#right").click(function() { $(".block").animate({ "left": "+=50px" }, "slow"); }); $("#left").click(function() { $(".block").animate({ "left": "-=50px" }, "slow"); }); 
 .block { position: absolute; background-color: #abc; left: 50px; width: 90px; height: 90px; margin: 5px; } .big_block { position: relative; left: 100px; right: 100px; background-color: red; height: 100px; width: 100px; overflow: hidden; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="left">&laquo;</button> <button id="right">&raquo;</button> <div class="big_block"> <div class="block"></div> </div> 

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

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