如果我理解正确,则将鼠标悬停在它上面时会移动该元素,这会导致hoverOut事件。您想在慢速鼠标移动时发生什么?它移动一次,保持移动,直到鼠标进入内部?
您需要在元素上设置一个变量,以显示它被移动10px的时间。然后你可以做类似(伪代码)
hoverIn() {
if (isShifted) {
inWhenShifted = true
} else {
// offset element
isShifted = true
}
hoverOut() {
if (isShifted) {
if (inWhenShifted) {
// put element back
isShifted = false
inWhenShifted = false
} else {
// do nothing?, this is the case where the hoverOut fired
// because we moved the element
}
} else {
// do nothing?, this is the case where we hoverOut again after shifting
// the element back
}
}