6

我有一个简单的画廊网格,其中包含一个显示标题的嵌套跨度,我想在鼠标悬停时向上滑动,并在鼠标移出时隐藏。

一切正常,除非鼠标向下移动到标题所在的位置和/或从图块底部悬停在图块之外,然后悬停效果会不受控制地重复几次。

起初我认为这可能是因为跨度包含在作为悬停触发器的锚点中,但将其移出也不起作用。

有任何想法吗 ?

演示在这里: 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);
    });
});
4

3 回答 3

8

这里的问题是每次鼠标移到元素或子元素上时都会触发 mouseover。尝试改用 mouseenter 和 mouseleave 事件。

于 2011-08-24T06:16:14.700 回答
4

尝试这个。

$(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-24T06:15:58.897 回答
0

所以你可能想要实现一个非常简单的锁定机制,如:

var fCurrentlyMoving = false;       
$('.gallery_container a').mouseover(function(){
    if (!fCurrentlyMoving) {
        fCurrentlyMoving = true;
        $(this).children('.title').animate({
            opacity: 100,
            bottom: 0
        },200, function() {
            fCurrentlyMoving = false;
        });
    }
});

这不是密封的比赛条件,但它不需要。

于 2011-08-24T06:12:16.743 回答