jQuery 按下某个键时捕获mousemove
jQuery capture mousemove when a certain key is pressed
如果假设键 H 被按下并且鼠标移动到某个 div.
上,我正在尝试捕获事件
KeyPressed
和 mouseMoving
都必须为真。
https://jsfiddle.net/bababalcksheep/1Loeh2pn/
代码:
$('#header').on("mousemove keydown", function(e) {
//only print if key 'H' is pressed and mouse is moving over $('#header')
if (e.type === 'mousemove' && e.which === 72) {
console.log('working');
}
});
这可能对您有所帮助。
https://jsfiddle.net/1Loeh2pn/3/
$(function() {
$("#header").hover(function() {
$(document).keydown(function(e) {
if(e.which == 72){
console.log('H')
}
});
});
});
如果假设键 H 被按下并且鼠标移动到某个 div.
上,我正在尝试捕获事件KeyPressed
和 mouseMoving
都必须为真。
https://jsfiddle.net/bababalcksheep/1Loeh2pn/
代码:
$('#header').on("mousemove keydown", function(e) {
//only print if key 'H' is pressed and mouse is moving over $('#header')
if (e.type === 'mousemove' && e.which === 72) {
console.log('working');
}
});
这可能对您有所帮助。
https://jsfiddle.net/1Loeh2pn/3/
$(function() {
$("#header").hover(function() {
$(document).keydown(function(e) {
if(e.which == 72){
console.log('H')
}
});
});
});