var _this = this
this.oDiv = document.getElementById(id)
this.disX = 0
this.disY = 0
this.oDiv.addEventListener("touchstart", function (ev) {
_this.fnDown(ev)
}, false)
}
PhoneDrag.prototype.fnDown = function (ev) {
var _this = this
var oEvent = ev.touches[0]
ev.preventDefault()
this.disX = oEvent.clientX - this.oDiv.offsetLeft
this.disY = oEvent.clientY - this.oDiv.offsetTop
// 解除事件绑定的时候需要用到
var touchmoveHandle = function (ev) {
_this.fnMove(ev)
}
document.addEventListener("touchmove", touchmoveHandle, false)
document.addEventListener("touchend", function (ev) {
//这里是手指抬起的时候 如何删除touchmove事件
document.removeEventListerner('touchmove', touchmoveHandle, false)
}, false)
}
PhoneDrag.prototype.fnMove = function (ev) {
var oEvent = ev.touches[0]
var iX = oEvent.clientX - this.disX
var iY = oEvent.clientY - this.disY
this.oDiv.style.top = iY + "px"
this.oDiv.style.left = iX + "px"
}
window.onload = function () {
new PhoneDrag("div1")
}