移動端長按事件

  // callback:長按回調dom

        // longTime:長按時間ide

        function LongTouch(dom, callback, longTime) {this

            var that = this;prototype

            that.dom = dom;事件

            that.fn = function() {rem

                var startTime = new Date().getTime();get

                that.timer = setInterval(function() {it

                    var endTime = new Date().getTime();io

                    if (endTime - startTime >= longTime) {function

                        callback();

                        clearInterval(that.timer);

                    }

                }, 10);

            }

            that.dom.addEventListener("touchstart", that.fn, false)

            that.dom.addEventListener("touchend", function() {

                clearInterval(that.timer);

            }, false);

        }

         // 解綁長按事件

        LongTouch.prototype.detachEvent = function() {

            var that = this;

            that.dom.removeEventListener("touchstart", that.fn, false);

        }

相關文章
相關標籤/搜索