mouseenter(进入)、mouseleave、mouseover(覆盖)和mouseout是常用来判断鼠标移出和移入的事件,虽然功能上差不多,但是细节却有不同的地方。


为了方便浏览,我将控制台的8个输出标记了序号,下面来说明一下(红色盒子为父盒子,蓝色盒子为子盒子):
①② 首先移入红色盒子范围内,触发了进入盒子的mouseover和mouseenter事件,且mouseover触发时间优先于mouseenter;
③④ 然后当移入到蓝色盒子时,触发了离开红色盒子的mouseout事件,同时触发了蓝色盒子mouseover进入事件,说明mouseover不仅在父元素会触发,在子元素也会触发;
⑤⑥ 再然后又移入红色盒子时,触发了蓝色盒子的mouseout事件和红色盒子的mouseover事件,同理说明mouseout不仅在父元素会触发,在子元素也会触发;
⑦⑧ 最后移出红色盒子时,触发mouseout和mouseleave事件。
网友评论