为jQuery添加Webkit的触摸的方法分享

2020-05-24 21:29:56易采站长站整理

这段代码是我在做13年一份兼职的时候无聊加上去的,为jQuery添加触摸事件的支持。因为做得有点无聊,所以就帮客户添加了用响应式网页+JS touch兼容了移动设备,主要是Webkit的移动设备。


这里就分享下我的实现。
先贴上代码:



//Published by Indream Luo
//Contact: indreamluo@qq.com
//Version: Chinese 1.0.0


!function ($) {
    window.indream = window.indream || {};
    $.indream = indream;


    //Define events
    indream.touch = {
        evenList: {
            touchStart: {
                htmlEvent: ‘touchstart’
            },
            touchMove: {
                htmlEvent: ‘touchmove’
            },
            touchEnd: {
                htmlEvent: ‘touchend’
            },
            tapOrClick: {
                eventFunction: function (action) {
                    $(this).each(function () {
                        (function (hasTouched) {
                            $(this).touchEnd(function (e) {
                                hasTouched = true;
                                action.call(this, e);
                            });
                            $(this).click(function (e) {