function onMouseMove(event) {
moveAt(event.pageX, event.pageY);
ball.hidden = true;
let elemBelow = document.elementFromPoint(event.clientX, event.clientY);
ball.hidden = false;
if (!elemBelow) return;
let droppableBelow = elemBelow.closest('.droppable');
if (currentDroppable != droppableBelow) {
if (currentDroppable) { // null when we were not over a droppable before this event
leaveDroppable(currentDroppable);
}
currentDroppable = droppableBelow;
if (currentDroppable) { // null if we're not coming over a droppable now
// (maybe just left the droppable)
enterDroppable(currentDroppable);
}
}
}
一开始,currentDroppable是null,判断不相等,然后:
如果此时球在球门上,则droppableBelow是真,currentDroppable也是真,进入球门
如果球不在球门上,则没有任何操作,保持原样;
假设上次进入球门了,currentDroppable是真
如果此时球在球门上,两者相同,没有变化;
如果不在了,则离开球门,current变为null,droppableBelow也是null,回到初始状态。