触摸事件只对移动设备有效
$(() => {
let elem = $(".clz")[0];
elem.ontouchstart = () => {
console.log("on touch start");
};
elem.ontouchmove = () => {
console.log("on touch move");
};
elem.ontouchend = () => {
console.log("on touch end");
};
});
版本比较低的移动设备,可能不支持ontouch方法,需要使用addEventListener方法来代替
$(() => {
let elem = $(".clz")[0];
elem.addEventListener("touchstart", () => {
console.log("on touch start");
});
elem.addEventListener("touchmove", () => {
console.log("on touch move");
});
elem.addEventListener("touchend", () => {
console.log("on touch end");
});
});