简体   繁体   English

jQuery mouseover淡入淡出效果

[英]jQuery mouseover fade effect

I've been learning how to do a Jquery mouse over effect from http://bavotasan.com/2009/creating-a-jquery-mouseover-fade-effect/ 我一直在从http://bavotasan.com/2009/creating-a-jquery-mouseover-fade-effect/学习如何将Jquery鼠标悬停在效果上

How do I have three separate buttons with this effect? 如何使用三个单独的按钮来实现此效果? I keep having a problem of the Divs overlapping when i duplicate them and I can't move them away from each other. 复制副本时,我总是遇到Divs重叠的问题,无法将它们彼此分开。 Sorry if my initial question was confusing! 抱歉,如果我的最初问题令人困惑! Here is my jsfiddle: http://jsfiddle.net/japaneselanguagefriend/EgDqy/ 这是我的jsfiddle: http : //jsfiddle.net/japaneselanguagefriend/EgDqy/

<div class="fadehover"><img src="button 1" alt="" class="a" /><img src="button 1 roll" alt="" class="b" /></div>

<div class="fadehover"><img src="button 2" alt="" class="c" /><img src="button 2 roll" alt="" class="d" /></div>

Here is a fiddle that should start you on the right path: 这是一个小提琴,应该让您开始正确的道路:

http://jsfiddle.net/EgDqy/12/ http://jsfiddle.net/EgDqy/12/

<div class="cell">

<img src="http://www.charlesayoub.com/news/public/uploads/images/895377521.jpeg" alt="" display /> 

<img src="http://static.ddmcdn.com/gif/smart-car-1.jpg" class="fader" alt="" />

</div>


<div class="cell"> 

<img src="http://www.charlesayoub.com/news/public/uploads/images/895377521.jpeg" alt="" /> 

<img src="http://static.ddmcdn.com/gif/smart-car-1.jpg" class="fader" alt="" />

</div>

<div class="cell"> 

<img src="http://www.charlesayoub.com/news/public/uploads/images/895377521.jpeg" alt="" /> 

<img src="http://static.ddmcdn.com/gif/smart-car-1.jpg" class="fader" alt="" />

</div>​


$(".cell").hover(
   function() {
      $(this).find('.fader').fadeOut("slow");
   },
   function() {
      $(this).find('.fader').fadeIn("slow");
   }
);


.cell{ width:100px; display:inline-block; position:relative; }
.cell img { width:100px; position:absolute; top:0; left:0; }

Basically because the inner elements of the div's are absolute positioned, the div's do not have any measurements (there is a technical word for this but is escapes me). 基本上因为div的内部元素是绝对定位的,所以div没有任何测量值(对此有一个专门的术语,但可以避免)。 You basically need to explicitly set the width and height of the div's. 基本上,您需要显式设置div的宽度和高度。 You can do this in CSS or dynamically generate the css in javascript/jquery. 您可以在CSS中执行此操作,也可以在javascript / jquery中动态生成CSS。 Here is an example using jquery. 这是使用jquery的示例。

http://jsfiddle.net/EgDqy/13/ http://jsfiddle.net/EgDqy/13/

Example paints a thousands words, this may help others understand the problem if they see this question. 示例描绘了数千个单词,如果其他人看到这个问题,这可能会帮助他们理解问题。 Click the button on the right 点击右边的按钮

http://jsfiddle.net/EgDqy/16/ http://jsfiddle.net/EgDqy/16/

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

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