2、移动端浏览器触摸事件: 事件名称 描述 是否包含 touches 数组 touchstart 触摸开始,多点触控,后面的手指同样会触发 是 touchmove 接触点改变,滑动时 是 touchend type="text/javascript"> $(function () { //手指触摸屏幕时触发事件 $('body').on('touchstart useCapture:true - 事件句柄在捕获阶段执行;false(默认) - 事件句柄在冒泡阶段执行 */ document.addEventListener('touchstart script type="text/javascript"> $(function () { //$(".move")[0].addEventListener("touchstart ", function (event) { document.addEventListener("touchstart", function (event) {
于是查了下touch的用法,发现是有touchstart,touchmove,touchend事件的,并且可以像click样直接使用。
今天要做一个页面div长按后触发事件,简单学习后实现如下: 先看代码: <template>
今天为大家介绍的事件主要是触摸事件:touchstart、touchmove和touchend。 一开始触摸事件touchstart、touchmove和touchend是iOS版Safari浏览器为了向开发人员传达一些信息新添加的事件。 下面具体说明: touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发。 touchmove事件:当手指在屏幕上滑动的时候连续地触发。 function load (){ document.addEventListener('touchstart',touch, false); document.addEventListener var oInp = document.getElementById("inp"); switch(event.type){ case "touchstart
$(document).bind(touchEvents.touchstart, function (event) { event.preventDefault(); 好办,仔细观察上面代码的触摸事件,touchEvents.touchXXX,看如下代码: var touchEvents = { touchstart: "touchstart", 否则默认触摸事件 */ initTouchEvents: function () { if (isPC()) { this.touchstart
JQuery写法 ---- 1 //手指开始触摸时,触发事件 2 $("#id").on('touchstart',function(e){ 3 4 var touch = e.originalEvent.targetTouches [0]; //取页面上第一个手指 5 6 var x_ distance = touch.pageX; //获取手指在X轴上距最左边的距离 7 8 }) 三个函数: touchstart -- touch.pageY --获取手指在Y轴上距最上边的距离 ---- 原生写法 1 //原生写法 2 document.getElementById("id").addEventListener("touchstart
工作中有时候会用到需要用代码去手动触发某个事件或者是自定义事件,通常触发click事件的做法为eleme.click(),遇到touchstart就行不通了。 可以使用以下方式 // 创建事件. var event = document.createEvent('Events'); // 初始化一个点击事件,可以冒泡,无法被取消 event.initEvent('touchstart ', true, false); // 设置事件监听. elem.addEventListener('touchstart', function (e) { // e.target 就是监听事件目标元素 elem.dispatchEvent(event); initEvent已经从 Web 标准中删除,虽然一些浏览器目前仍然支持它,不建议再使用此方法,可以使用Event构造函数 var event = new Event('touchstart '); //监听 elem.addEventListener('touchstart', function (e) { ... }, false); // 触发event. elem.dispatchEvent
在屏幕上双击进行放大(单击300ms后,再单击才算双击),造成了,移动端点击事件,300ms 延迟的问题 解决方案,就是使用touch事件来替代 移动端新增touch事件 --- 只能使用现代事件进行添加 touchstart luo1240465012-p-9450627.html 添加touch 事件 代码如下: <script type="text/javascript"> document.addEventListener('touchstart ', function () { console.log( 'touchstart' ); , false); document.addEventListener( 'touchmove ', function <script type="text/javascript"> document.addEventListener( 'touchstart', function (e) { console.log } }, tap: function (callback){ this.elem.addEventListener( 'touchstart
PC 端添加效果使用 mouseup、mousedown、mousemove,而移动端使用的 touchstart、touchmove、touchend 。 touchcancel - 触摸过程中被系统取消时触发 (很少使用) touch 事件与mouse事件区别: touchstart:手指按下,mousedown:鼠标按下。 touchstart: 只能在绑定元素内按下触发,touchmove、touchend可以在屏幕的任意位置执行。而 mousedown、mousemove、mouseup 都只能在绑定元素内执行。 touchmove、touchend 只能在 touchstart 触发后,才能执行。但是 mousemove 只要鼠标在绑定元素上,不按下也能执行。 触摸事件跟鼠标事件的触发先后顺序: Touchstart > toucheend > mousemove > mousedown > mouseup > click
为了解决开发者需要,建议开发者在touchstart时调用event.preventDefault,这样就可以保证内核会一起触发touchmove事件了。 之后继续百度,得知当在移动端上点击屏幕时,会依次触发touchstart,touchmove,touchend,click事件。 之后测试了一下,发现正确的触发过程应该是:touchstart→touchmove→touchend或者touchstart→touchend→click。 之后我大胆推测了一下: 会不会是因为在移动端click事件的触发条件就是必须touchstart和touchend同时触发才能触发click呢? 我在touchstart中调用了event.preventDefault方法,是不是让浏览器误以为没有触发touchstart事件,只触发了touchend事件,所以没有触发click事件呢?
后者将中断捕获阶段和取消冒泡阶段 示例: 点击 inner view 会先后调用handleTap2、handleTap4、handleTap3、handleTap1 <view id="outer" bind:touchstart ="handleTap1" capture-bind:touchstart="handleTap2"> outer view <view id="inner" bind:touchstart=" handleTap3" capture-bind:touchstart="handleTap4"> inner view </view> </view> 如果把上面的代码改成如下,将只会触发 handleTap2 <view id="outer" bind:touchstart="handleTap1" capture-catch:touchstart="handleTap2"> outer view <view id="inner" bind:touchstart="handleTap3" capture-bind:touchstart="handleTap4"> inner
的嚎叫可以用下面代码归纳 $(document) .on('touchstart }); Android 4.4 touch事件 长距离的滑动: touchstart - > touchmove(仅一次) -> touchcancel 短距离: touchstart - > touchmove(一次) -> touchend 事情发展到了这里,去下载最新的zepto 看破红尘,上面的都不重要 Android 4.4 长距离的滑动touchmove只发生一次是不是让充满爱的FE瞬间变得忧伤了~ 哈~,其实只需touchmove时e.preventDefault() touchstart - > touchmove(仅一次) -> touchcancel 就能变成 touchstart - > touchmove(多次) -> touchend (也不再是touchcancel了
其他浏览器暂未考虑到 一、事件定义及分类 1. click事件 单击事件,类似于PC端的click,但在移动端中,连续click的触发有200ms ~ 300ms的延迟 2. touch类事件 触摸事件,有touchstart touchmove touchend touchcancel 四种之分 touchstart:手指触摸到屏幕会触发 touchmove:当手指在屏幕上移动时,会触发 touchend:当手指离开屏幕时 2) 查看触发的事件对象 简单地修改,将事件监听中第三个参数置为true,输出完整的事件对象 addEvent(one, 'tap click touchstart touchmove touchend 2、第二根手指放下,触发gesturestart 3、触发第二根手指的touchstart 4、立即触发gesturechange 5、手指移动,持续触发gesturechange 6、第二根手指提起 touchstart) 9、提起第一根手指,触发touchend 还有其他事件有待发觉... gestureend
PC 端添加效果使用 mouseup、mousedown、mousemove,而移动端使用的 touchstart、touchmove、touchend 。 touchcancel - 触摸过程中被系统取消时触发 (很少使用) touch 事件与mouse事件区别: touchstart:手指按下,mousedown:鼠标按下。 touchstart: 只能在绑定元素内按下触发,touchmove、touchend可以在屏幕的任意位置执行。而 mousedown、mousemove、mouseup 都只能在绑定元素内执行。 touchmove、touchend 只能在 touchstart 触发后,才能执行。但是 mousemove 只要鼠标在绑定元素上,不按下也能执行。 触摸事件跟鼠标事件的触发先后顺序: Touchstart > toucheend > mousemove > mousedown > mouseup > click
的嚎叫可以用下面代码归纳 $(document) .on('touchstart }); Android 4.4 touch事件 长距离的滑动: touchstart - > touchmove(仅一次) -> touchcancel 短距离: touchstart - > touchmove(一次) -> touchend 事情发展到了这里,去下载最新的zepto ,上面的都不重要 Android 4.4 长距离的滑动touchmove只发生一次是不是让充满爱的FE瞬间变得忧伤了~ 哈~,其实只需touchmove时e.preventDefault() touchstart - > touchmove(仅一次) -> touchcancel 就能变成 touchstart - > touchmove(多次) -> touchend (也不再是touchcancel
="touchstartfunc">div> <div on:touchstart="touchstartfunc">div> <div grab:touchstart.bubble ="touchstartfunc">div> <div grab:touchstart="touchstartfunc">div>
PC 端添加效果使用 mouseup、mousedown、mousemove,而移动端使用的 touchstart、touchmove、touchend 。 touchcancel - 触摸过程中被系统取消时触发 (很少使用) touch 事件与mouse事件区别: touchstart:手指按下,mousedown:鼠标按下。 touchstart: 只能在绑定元素内按下触发,touchmove、touchend可以在屏幕的任意位置执行。而 mousedown、mousemove、mouseup 都只能在绑定元素内执行。 touchmove、touchend 只能在 touchstart 触发后,才能执行。但是 mousemove 只要鼠标在绑定元素上,不按下也能执行。 触摸事件跟鼠标事件的触发先后顺序: Touchstart > toucheend > mousemove > mousedown > mouseup > click
最基本的touch事件包括4个事件: touchstart: 当在屏幕上按下手指时触发 touchmove: 当在屏幕上移动手指时触发 touchend: 当在屏幕上抬起手指时触发 touchcancel 2.2 touchstart事件 当用户手指触摸到的触摸屏的时候触发。事件对象的 target 就是touch 发生位置的那个元素。
的嚎叫可以用下面代码归纳 $(document) .on('touchstart }); Android 4.4 touch事件 长距离的滑动: touchstart - > touchmove(仅一次) -> touchcancel 短距离: touchstart - > touchmove(一次) -> touchend 事情发展到了这里,去下载最新的zepto 看破红尘,上面的都不重要 Android 4.4 长距离的滑动touchmove只发生一次是不是让充满爱的FE瞬间变得忧伤了~ 哈~,其实只需touchmove时e.preventDefault() touchstart - > touchmove(仅一次) -> touchcancel 就能变成 touchstart - > touchmove(多次) -> touchend (也不再是touchcancel了
PC 端添加效果使用 mouseup、mousedown、mousemove,而移动端使用的 touchstart、touchmove、touchend 。 touchcancel - 触摸过程中被系统取消时触发 (很少使用) touch 事件与mouse事件区别: touchstart:手指按下,mousedown:鼠标按下。 touchstart: 只能在绑定元素内按下触发,touchmove、touchend可以在屏幕的任意位置执行。而 mousedown、mousemove、mouseup 都只能在绑定元素内执行。 touchmove、touchend 只能在 touchstart 触发后,才能执行。但是 mousemove 只要鼠标在绑定元素上,不按下也能执行。 触摸事件跟鼠标事件的触发先后顺序: Touchstart > toucheend > mousemove > mousedown > mouseup > click