我有一个简单的画廊网格,它有一个嵌套的跨度,显示标题,我想在鼠标上滑动,并在鼠标移出时隐藏。
一切正常,除非鼠标向下移动到标题所在的位置和/或从磁贴底部悬停在磁贴之外,然后无法控制地重复几次悬停效果。
起初我认为这可能是因为跨度包含在锚点内,而锚点是悬停触发器,但将其移出也不起作用。
有什么想法吗?
演示在这里:http://www.winterealm.com/gallery/
标记:
<div class="gallery_container">
<ul>
<li><a href=""><img src="assets/img/artistisch.jpg" alt="aaa"/><span class="title">Category A</span></a></li>
<li><a href=""><img src="assets/img/attraktiv.jpg" alt="bbb"/><span class="title">Category B</span></a></li>
<li><a href=""><img src="assets/img/historisch.jpg" alt="ccc"/><span class="title">Category C</span></a></li>
<li><a href=""><img src="assets/img/popart.jpg" alt="ddd"/><span class="title">Category D</span></a></li>
<li><a href=""><img src="assets/img/portrait.jpg" alt="eee"/><span class="title">Category E</span></a></li>
<li><a href=""><img src="assets/img/sketch.jpg" alt="fff"/><span class="title">Category F</span></a></li>
</ul>
</div>下面是jquery
$(document).ready(function(){
$('.gallery_container a').mouseover(function(){
$(this).children('.title').animate({
opacity: 100,
bottom: 0
},200);
});
$('.gallery_container a').mouseout(function(){
$(this).children('.title').animate({
opacity: 0,
bottom: -30
},200);
});
});发布于 2011-08-24 14:16:15
这里的问题是,每次鼠标移到元素或子元素上时都会触发鼠标悬停。请尝试使用mouseenter和mouseleave事件。
发布于 2011-08-24 14:15:59
尝尝这个。
$(document).ready(function() {
$('.gallery_container a').hover(function() {
$(this).children('.title').stop().animate({
opacity: 100,
bottom: 0
}, 200);
}, function() {
$(this).children('.title').stop().animate({
opacity: 0,
bottom: -30
}, 200);
});
});你可以在这里看到一个现场演示。- http://jsfiddle.net/8Hd7s/
发布于 2011-08-24 14:12:17
因此,您可能希望实现一个非常简单的锁定机制,如下所示:
var fCurrentlyMoving = false;
$('.gallery_container a').mouseover(function(){
if (!fCurrentlyMoving) {
fCurrentlyMoving = true;
$(this).children('.title').animate({
opacity: 100,
bottom: 0
},200, function() {
fCurrentlyMoving = false;
});
}
});这不是无懈可击的比赛条件,但它不需要是。
https://stackoverflow.com/questions/7171128
复制相似问题