1.移动端使用的是touch事件,但不能直接通过ontouch等语法访问,需要使用addEventListener进行绑定
2.可选事件
- touchstart:手指触摸时触发
- touchmove:手指在屏幕上滑动时连续触发
- touchend:当手指离开屏幕时触发。
- touchcancel:系统停止跟踪触摸时候会触发。(这个事件使用较少,了解即可)
- 事件参数中 能够获取移动的一些属性
dom.addEventListener('touchstart',function(e){
console.log(e.targetTouches); //目标元素的所有当前触摸
console.log(e.changedTouches);//最新更改的所有触摸
console.log(e.touches);//所有的触摸
})
1.touchstart:触摸的时候出发
2.touchmove:触摸并移动的时候被触发
2.touchend:触摸结束的时候被触发
window
.onload =
function
(){
//元素的事件 绑定时如果写了形参 会绑定一个实参
//触摸 开始的时候被触发
document
.
body
.
addEventListener
(
'touchstart'
,
function
(event){
console
.
log
(
'touchstart'
)
;
console
.
log
(event)
;
})
;
//手指移动的时候会一直触发
document
.
body
.
addEventListener
(
'touchmove'
,
function
(event){
console
.
log
(
'touchmove'
)
;
console
.
log
(event)
;
})
;
//手指抬起来的时候会触发
document
.
body
.
addEventListener
(
'touchend'
,
function
(event){
console
.
log
(
'touchend'
)
;
console
.
log
(event)
;
})
}
在
console
.
log
(event)
;
后出来的一堆东西里面
表示的是用户多个手指触摸