【发布时间】:2012-02-10 13:57:48
【问题描述】:
我在freakyleaf.co.uk/hoverfade/ 有以下实时示例,当将鼠标悬停在磁贴上时,磁贴背景图像在 600 毫秒 (.tile_img) 内从 1 淡化到 0.25 不透明度,然后在 500 毫秒 (.overlay) 内将文本从 0 淡化到 1 不透明度)。在鼠标移出时,会发生相反的情况。
只要鼠标在鼠标悬停动画完成后离开,这一切都可以正常工作。如果鼠标在鼠标悬停动画期间离开,平铺图像会逐渐变回完全不透明度,但文本不会褪色,而是可见。
我有以下代码:
$(document).ready(function(){
$(".tile").hoverIntent(function() {
$(".tile_img", this).animate({"opacity": "0.25"}, 600,
function() { $(this).next(".overlay").animate({"opacity": "1"}, 500); }
);
},
function() {
$(".overlay", this).animate({"opacity": "0"}, 500,
function() { $(this).prev(".tile_img").animate({"opacity": "1"}, 600); }
);
});
});
还有 HTML:
<div class="wrapper">
<ul id="service_boxes">
<li id="sb_recording" class="tile" onClick="location.href='recording.php';" style="cursor: pointer;">
<h2><a href="recording.php">Recording</a></h2>
<div class="tile_img"></div>
<div class="overlay"><p>Vintage analogue warmth and cutting-edge digital technology working in perfect harmony - That's the SoundARC sound!</p></div>
</li>
</ul>
</div>
我知道我也许应该使用 .stop 函数,但我在几个地方尝试过,但到目前为止只破坏了代码。
我什至不确定我所拥有的是否是实现我想要的最佳方式;由于我是一个完全的新手,我只是偶然地走到了这一步。
任何帮助将不胜感激。
非常感谢。
【问题讨论】:
标签: jquery hover jquery-animate mouseover mouseout