html5 touch 事件用在哪儿

html5 touch 事件用在哪儿,第1张

touchstart事件:当手指触摸屏幕时候触发,即使已经有一个手指放在屏幕上也会触发。

touchmove事件:当手指在屏幕上滑动的时候连续地触发。在这个事件发生期间,调用preventDefault()事件可以阻止滚动。

touchend事件:当手指从屏幕上离开的时候触发。

touchcancel事件:当系统停止跟踪触摸的时候触发。关于这个事件的确切出发时间,文档中并没有具体说明,咱们只能去猜测了。

//选中条件 x1=横轴位置 y1=纵轴位置 

var x1, x2, y1, y2

$(document).on("touchstart",".smallbox", function (e) {

// e.preventDefault()

var obj = $(this)

var position = $(this).offset()

x1 = position.left

x2 = position.left + obj.width()

y1 = position.top

y2 = position.top + obj.height()//触摸时将变量赋值

}).on("touchend", ".smallbox", function (e) {

var pos = e.originalEvent.changedTouches[0]

if (pos.pageX >= x1

&& pos.pageX <= x2

&& pos.pageY >= y1

&& pos.pageY <= y2) {//判断当前的点击位置是否在有效范围内

var obj = $(this)

if (obj.hasClass("active")) {

obj.removeClass("active")

} else {

obj.addClass("active")

}

}

e.preventDefault()

}).on("click", ".smallbox", function () {

var obj = $(this)

if (obj.hasClass("active")) {

obj.removeClass("active")

} else {

obj.addClass("active")

}

})


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5898277.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-03-07
下一篇 2023-03-07

发表评论

登录后才能评论

评论列表(0条)

保存