Box.addEventListener('mousedown', function () {
console.log('鼠标按下')
})
Box.addEventListener('mousemove', function () {
console.log('鼠标移动')
})
Box.addEventListener('mouseup', function () {
console.log('鼠标抬起')
})
Box.addEventListener('touchstart',function (){
console.log('手指按下')
})
Box.addEventListener('touchmove',function (){
console.log('手指移动')
})
Box.addEventListener('touchend',function (){
console.log('手指抬起')
})
touch 事件 和 mouse 事件的区别:
- mousedown:鼠标按下 touchstart:手指触摸
- mousemove:鼠标移动 touchmove:手指移动
- moveup:鼠标抬起 touchend:手指抬起
- touch事件只能在移动端使用;mouse事件只能在PC端使用;
- touch事件的touchstart只能在元素内触发,touchmove和touchend可以在屏幕任意位置触发;
- mouse事件都只能在元素内触发;
- touch事件只有在touchstart触发后,才能触发touchmove和touchend事件;但mouse事件的mousemove只要在元素内没有鼠标按下也能触发