长按 模拟事件

触摸事件

touchstart 触摸开始,多点触控,后面的手指同样会触发。
touchmove 接触点改变,滑动时触发。
touchend 触摸结束,手指离开屏幕时触发。
touchcancel 触摸被取消,当系统停止跟踪触摸的时候触发。

触摸事件详情介绍原文链接:https://blog.csdn.net/wangmx1993328/article/details/83270166

以下为本次模拟长安按事件:


longPress(id, func) {
        var timeOutEvent;
        //取得长按元素id
        document.querySelector('#WxZlTalentPoster').addEventListener('touchstart', function (e) {
            clearTimeout(timeOutEvent);
            timeOutEvent = setTimeout(function () {   // 长按触发后的回调函数
                console.log(12112111);
                // func();
            }, 1000);    //设置长按时间 (在多长时间后触发)
        });

        document.querySelector('#WxZlTalentPoster').addEventListener('touchmove', function (e) {
             //判断吗是否为 手指在屏幕滑动  是的话清除定时器;
            clearTimeout(timeOutEvent);
        });

        document.querySelector('#WxZlTalentPoster').addEventListener('touchend', function (e) {
             //判断吗是否为 手指从屏幕时移开  是的话清除定时器;
            clearTimeout(timeOutEvent);
        });
    }



加油哦!

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容