美文网首页
移动端Touch事件

移动端Touch事件

作者: Pretty_Boy | 来源:发表于2017-08-06 17:06 被阅读141次

    touchstart: //手指放到屏幕上时触发
    touchmove: //手指在屏幕上滑动式触发
    touchend: //手指离开屏幕时触发

    每个触摸事件被触发后,会生成一个event对象
    targetTouches: //当前dom元素上手指的列表,尽量使用这个代替touches,如果有一个手指则event.targetTouches[0]

    属性如下:
    clientX / clientY: //触摸点相对浏览器窗口的位置
    pageX / pageY: //触摸点相对于页面的位置
    screenX / screenY: //触摸点相对于屏幕的位置
    identifier: //touch对象的ID
    target: //当前的DOM元素

    注意:
    手指在滑动整个屏幕时,会影响浏览器的行为,比如滚动和缩放。所以在调用touch事件时,要注意禁止缩放和滚动。
    1.禁止缩放
    通过meta元标签来设置。
    2.禁止滚动
    preventDefault是阻止默认行为,touch事件的默认行为就是滚动。
    event.preventDefault();

    相关文章

      网友评论

          本文标题:移动端Touch事件

          本文链接:https://www.haomeiwen.com/subject/cipglxtx.html