简体   繁体   English

鼠标悬停在图像上的效果

[英]mouse hover effect on image

将鼠标悬停在图像上之前

将鼠标悬停在图像上之后

initially image only visible and the buttons are hide back of image. 最初仅图像可见,按钮向后隐藏。 On image mouse hover the image going little top and buttons will come on bottom of image. 将鼠标悬停在图像上时,图像会移到小顶部,而按钮将位于图像的底部。 but how to hide the buttons back in image?? 但是如何将按钮隐藏回图像中?

before mouse hover the image only visible after mouse hover on image messup and visible the buttons. 鼠标悬停之前,只有将鼠标悬停在图像消息上并可见按钮之后,图像才可见。 i tried like this but not getting, here snippet for reference ( http://www.olleep.com/ ) im trying to do same 我试图这样但没有得到,这里的片段供参考( http://www.olleep.com/ )我试图做同样的事情

 $(document).ready(function() { $('#textbox').mouseenter(function() { $('#textbox').animate({ 'marginTop' : "-=30px" //moves up }); }); $('#textbox').mouseleave(function() { $('#textbox').animate({ 'marginTop' : "+=30px" //moves up }); }); }); 
 .container{ margin:50px; } #textbox{ position:relative; width:300px; } #text{ position:relative; overflow:hidden; z-index:1; background-color:#282727; text-align:center; padding:10px 10px 10px 10px; } 
 <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div id="textbox"> <img src="http://i.imgur.com/9hr2mlL.png" width="300px"> <div id="text"> <button class="btn btn-danger btn-md">MORE INFO</button> <button class="btn btn-danger btn-md">BOOK NOW</button></div> </div> </div> 

You can do this with CSS alone, still with adding hover effects, then using transform:translateY to toggle these on screen: 您可以单独使用CSS进行此操作,仍然可以添加悬停效果,然后使用transform:translateY在屏幕上切换这些效果:

 div { display: inline-block; } .wrapper { overflow: hidden; position:relative; } .buttons{ position:absolute; bottom:0; width:100%;background:dimgray; font-size:0;height:40px; transition:all 0.4s; transform:translateY(100%); } .buttons button{ width:40%;margin:5%;font-size:15px; } .wrapper img{ transition:all 0.4s;} .wrapper:hover .buttons{ transform:translateY(0); } .wrapper:hover img{ transform:translateY(-35px); } 
 <div class="wrapper"> <img src="http://i.imgur.com/9hr2mlL.png" /> <div class="buttons"> <button>Button 1</button> <button>Button 2</button> </div> </div> 

You can use CSS to do that. 您可以使用CSS来做到这一点。 Try :hover , check below example. 尝试:hover ,检查下面的示例。

 .container { margin: 50px; } #textbox { position: relative; width: 300px; } #text { position: relative; overflow: hidden; z-index: 1; background-color: #282727; text-align: center; padding: 10px 10px 10px 10px; display: none; } #textbox:hover #text { display: block; } 
 <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" /> <div class="container"> <div id="textbox"> <img src="http://i.imgur.com/9hr2mlL.png" width="300px"> <div id="text"> <button class="btn btn-danger btn-md">MORE INFO</button> <button class="btn btn-danger btn-md">BOOK NOW</button> </div> </div> </div> 

Add $('#text').show(); 添加$('#text').show(); and $('#text').hide(); $('#text').hide();

 $(document).ready(function() { $('#textbox').mouseenter(function() { $('#text').show(); $('#textbox').animate({ 'marginTop' : "-=30px" //moves up }); }); $('#textbox').mouseleave(function() { $('#text').hide(); $('#textbox').animate({ 'marginTop' : "+=30px" //moves up }); }); }); 
 .container{ margin:50px; } #textbox{ position:relative; width:300px; } #text{ position:relative; overflow:hidden; z-index:1; background-color:#282727; text-align:center; padding:10px 10px 10px 10px; } 
 <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> <link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/> <div class="container"> <div id="textbox"> <img src="http://i.imgur.com/9hr2mlL.png" width="300px"> <div id="text"> <button class="btn btn-danger btn-md">MORE INFO</button> <button class="btn btn-danger btn-md">BOOK NOW</button></div> </div> </div> 

You can do it with simple .hide() and .show() 你可以用简单的做.hide().show()

Check this http://codepen.io/vigneshvdm/pen/PNLJKL 检查此http://codepen.io/vigneshvdm/pen/PNLJKL

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

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