jQuery Mouseenter事件未触发它在点击时触发

时间:2013-12-03 16:42:11

标签: javascript jquery jquery-collision

jQuery mouseenter事件未在鼠标中触发,单击

时触发它
function showOverlap() {
    var hits = $('.follower').collision('#slides li');
    $(hits).trigger('mouseenter');
}

$('.container1').mouseenter(function() {
    showOverlap();
});

$('#slides li').on('mouseenter',function(){
    $('#slides li').removeClass('selectedMenu');
    $(this).addClass('selectedMenu');
});

JsBin http://jsbin.com/urEpESAM/19/edit

如果在mouseMove中写入mouseenter事件但是速度慢得多

,这里工作正常

3 个答案:

答案 0 :(得分:1)

试试这个

$(document).on({
    mouseenter: function() {
        $('#slides li').removeClass('selectedMenu');
        $(this).addClass('selectedMenu');
    },
    mouseleave: function() {
       // Do stuff when mouse leaves `#slides li`
    }
}, "#slides li");

答案 1 :(得分:0)

如果要触发mouseenter事件,则需要绑定该事件。你的问题不是mouseenter。

看看这里:http://jsfiddle.net/stryd3r/mA3wy/

您的问题排在第:$(hits).trigger('mouseenter');

答案 2 :(得分:0)

这应该可以解决问题:

 function showOverlap() {
    var hits = $('.follower').collision('#slides li');
    $(hits).trigger('mouseenter');
}

$('.container1').mouseenter(function() {
    showOverlap();
});

$(this).bind('mouseenter',function(){
    alert("in");
    $('#slides li').removeClass('selectedMenu');
    $(this).addClass('selectedMenu');
});

Demo