$( "#list li:eq(0)" ).bind('mouseenter focus', function(event) {
jQuery("#logo img").css('top', '-132px');
console.log( event.type, " :: ", this.id );
}).bind('blur mouseleave', function(event) {
jQuery("#logo img").css('top', '-41px');
console.log( event.type, " :: ", this.id );
});
Этот кусок jQuery отлично работает с мышью, но не с клавишей табуляции! Вы сталкиваетесь с аналогичной проблемой?
Я пробовал .bind, чтобы запустить оба события и до сих пор не работает!
, если запускает событие в центре мыши, но ничего не фокусируется!
mouseenter
and mouseleave
have nothing to do with keyboard events, and are not fired when an element gains keyboard focus
.
Чтобы ваш код работал как на mouseenter
, так и на focus
, это немного ближе:
$("#MesActivites li:eq(0)").bind("mouseenter focus", function (event) {
jQuery("#MesActivites ul:eq(1)").css('top', '45px').css('left', '-1px');
jQuery("#rfr-header-logo").css('display', 'none');
console.log(event.type, " :: ", this.id);
}).bind("mouseleave blur", function (event) {
jQuery("#MesActivites ul:eq(1)").css('top', '-1000px').css('left', '-1px');
jQuery("#rfr-header-logo").css('display', 'block');
console.log(event.type, " :: ", this.id);
});
События мыши обычно не срабатывают при нажатии клавиш. .focus ()
и .blur ()
- это то, что вам нужно.
Изменить: большинство неформатных элементов не могут принять фокус по умолчанию, вам нужно добавить к ним атрибут tabindex
:
...