使用jQuery动画时丢失悬停(不移动鼠标)

FFi*_*ish 7 javascript mouse jquery hover jquery-animate

我有这一行缩略图,我用jQuery动画.
这些缩略图中的每一个都有一个悬停和活动类.

它们工作正常但是当我为列表设置动画时,鼠标光标下的新缩略图不会应用悬停?每次点击后我都要移动鼠标一点点?

这有点困难.我在这里做了一个小提琴:http://jsfiddle.net/nZGYA/
当你开始点击拇指3而不移动鼠标你就会明白我的意思...

它在FireFox中运行良好,而不是Safari,Chrome,IE等.
我可以做些什么吗?

这里参考我的代码:

<style type="text/css">
    .container { position: relative; overflow: hidden; width: 140px; height: 460px; float: left; margin-right: 100px; background: silver;  }            
    ul { position: absolute; top: 10; list-style: none; margin: 10px; padding: 0; }
    li { margin-bottom: 10px; width: 120px; height: 80px; background: gray; }
    #list-2 li a { display: block; width: 120px; height: 80px; outline: none; }
    #list-2 li a:hover { background: teal; }
    #list-2 li a.active { background: navy; }
</style>

$(document).ready(function() {
    var idx_2 = 0;
    $('#list-2 li a')
    .click(function() {
        $('#list-2 > li a').removeClass('active');
        $(this).addClass('active');         
        var id =  $('#list-2 li a.active').data('index') - 2;
        idy = Math.max(0, id * 90);
        $(this).parent().parent().animate({ 'top' : -idy + 'px' });
        return false;
    })
    .each(function() {
        $(this).data('index', idx_2);
        ++idx_2;
    });
});

<div class="container">
    <ul id="list-2">
        <li><a class="active" href="#"></a></li>
        <li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li>
        <li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li>
        <li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li>
        <li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li>
        <li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li>
        <li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li><li><a href="#"></a></li>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

jim*_*mig 1

我有一个适用于 Chrome 和 IE 的解决方案(尚未在 Safari 中测试)。基本上,如果缩略图已移动,我会在 animate() 回调事件中触发鼠标下方元素的 mouseover() 事件。该解决方案仅针对 list-1 实施。

// list 1
var idx = 0;
$('#list-1 li').hover(function() {
    $(this).addClass('hover');
}, function() {
    $(this).removeClass('hover');
}).click(function() {
    $('#list-1 > li').removeClass('active');
    var $active = $(this);
    $active.addClass('active');
    var id = $('#list-1 li.active').data('index') - 2; // take scroll param and subtract 2 to keep selected image in the middle

    var moveAmount = 90;
    idy = Math.max(0, id * moveAmount);
    var oldPos = $active.parent().position().top;

    $active.parent().animate({
        'top': -idy + 'px'
    }, function(){

        var newPos = $(this).position().top;

        // Check if we moved
        if(oldPos - newPos != 0)
        {
            var movement = (oldPos - newPos) / moveAmount;
            $($(this).children()[$active.index() + movement])
                .trigger("mouseover");

        }

    });
    return false;
}).css('cursor', 'pointer').each(function() {
    $(this).data('index', idx);
    ++idx;
});
Run Code Online (Sandbox Code Playgroud)

如果你不想在那里测试它,这里是我在 jsfiddle 中的分支的链接 - http://jsfiddle.net/jimmysv/3tzAt/15/