This commit is contained in:
qianguyihao
2019-11-12 17:16:46 +08:00
parent fbb8c34468
commit e947d2d9f8
3 changed files with 10 additions and 11 deletions

View File

@@ -248,12 +248,12 @@ event.cancelBubble = true
var pagey = event.pageY || scroll().top + event.clientY;
// 设置div的偏移量相对于整个页面
// 注意,如果想通过 style.left 来设置属性,一定要给 box1开启绝对定位。
// 注意,如果想通过 style.left 来设置属性,一定要给 box1 开启绝对定位。
box1.style.left = pagex + 'px';
box1.style.top = pagey + 'px';
};
// 【重要注释】
// 【重要注释】
// 当 document.onmousemove 和 box2.onmousemove 同时触发时,通过 box2 阻止事件向 document 冒泡。
// 也就是说,只要是在 box2 的区域,就只触发 document.onmousemove 事件
var box2 = document.getElementById('box2');
@@ -286,12 +286,13 @@ event.cancelBubble = true
</html>
```
关键地方可以看代码中的注释。
效果演示:
![](http://img.smyhvae.com/20191112_1650.gif)
## 我的公众号
想学习<font color=#0000ff>**代码之外的技能**</font>?不妨关注我的微信公众号:**千古壹号**id`qianguyihao`)。