我有这个功能
$('*').hover(
function (e) {
mouseX = e.pageX;
mouseY = e.pageY;
var elem = document.elementFromPoint(mouseX, mouseY);
$(elem).addClass('hoverElem');
},
function (e) {
mouseX = e.pageX;
mouseY = e.pageY;
var elem = document.elementFromPoint(mouseX, mouseY);
$(elem).removeClass('hoverElem');
}
);
这适用于第一个功能,但第二个功能没有做任何事情,任何想法如何解决它?
答案 0 :(得分:0)
这是解决方案:
$('*').hover(
function (e) {
$(this).addClass('hoverElem');
},
function (e) {
$(this).removeClass('hoverElem');
}
);
答案 1 :(得分:0)
请改为尝试:
$('*').hover(
function (e) {
// Remove class from previous element
$('.hoverElem').removeClass('hoverElem');
// Add class to new element
mouseX = e.pageX;
mouseY = e.pageY;
var elem = document.elementFromPoint(mouseX, mouseY);
$(elem).addClass('hoverElem');
}
);
或者这个:
$('*').hover(
function (e) {
// Add class to new element
mouseX = e.pageX;
mouseY = e.pageY;
var elem = document.elementFromPoint(mouseX, mouseY);
$(elem).addClass('hoverElem');
}, function (e) {
// Remove class from previous element
$('.hoverElem').removeClass('hoverElem');
}
);
我不确定你要做什么,所以有点难以猜测。