mouseDown,mouseMove,mouseUp更好的实践
作者:互联网
不好的实践,move 不能太快,否则会监听不到
let flag = false
document.addEventListener('mousedown', down)
document.addEventListener('mousemove', move)
document.addEventListener('mouseup', up)
function down() {
flag = true
// ......
}
function move(e) {
e.preventDefault()
if(!flag) return
// .....
}
function up() {
flag = false
// ......
}
较好的实践,这样可以快速的 mousemove,不会监听不到
document.addEventListener('mousedown', down)
document.addEventListener('mouseup', up)
function down() {
document.addEventListener('mousemove', move)
}
function move(e) {
e.preventDefault()
}
function up() {
document.removeEventListener('mousemove', move)
}
标签:function,move,mouseUp,mouseMove,down,mouseDown,addEventListener,mousemove,docume 来源: https://www.cnblogs.com/Lilc20201212/p/16439127.html