简体   繁体   English

向下滑动并向上滑动

[英]Slide down and slide up reverse

When hovering over div, second div slides down, and when not hovering slides back up. 将鼠标悬停在div上时,第二个div向下滑动,不悬停时将其向上滑动。 I am having issues in doing it the other way. 我在以其他方式执行操作时遇到问题。 Is there a way of making the div slide up on hover, and slide back down when not hovering? 有没有一种方法可以使div在悬停时向上滑动,而在不悬停时向下滑动呢? So essentially, it slides up into the hovering div 因此从本质上讲,它滑入了悬停的div

 function animationRollover(element, rollover) { $(element).hover(function() { $(rollover).slideDown(); }, function() { $(rollover).slideUp(); }); }; animationRollover('#divImage1', '#divTextImage1'); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="divImage1" style="float: left; width: 280px; margin-left: 40px; border: 1px solid"> <div style="height: 50px;"> test </div> <div id="divTextImage1" style="width: 280px; height: 20px; background-color: rgba( 0,0,0,0.6 ); float: left; position: absolute; opacity: 0.5; color: white; display: none;"> test </div> </div> 

Remove display: none; 删除display: none; from <div id='divTextImage1'" ..> style attribute and invert slideUp with slideDown . <div id='divTextImage1'" ..>风格属性和反转slideUpslideDown

 function animationRollover(element, rollover) { $(element).hover(function() { $(rollover).slideUp(); }, function() { $(rollover).slideDown(); }); }; animationRollover('#divImage1', '#divTextImage1'); 
 #divImage1 { position: relative; } #divTextImage1 { position: absolute; bottom: 0; } 
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="divImage1" style="float: left; width: 280px; margin-left: 40px; border: 1px solid"> <div style="height: 50px;"> test image <div id="divTextImage1" style="width: 280px; height: 20px; background-color: rgba( 0,0,0,0.6 ); float: left; position: absolute; opacity: 0.5; color: white;"> test text </div> </div> </div> 

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

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