ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
##Javascript 原生Touch事件 ~~~ var b = document.getElementsByTagName("body")[0]; b.addEventListener("touchmove", function(e){ e.preventDefault(); }); (function(){ var startX,startY,endX,endY,moveLength; var el = document.querySelector("#demo"); //获取点击开始的坐标 el.addEventListener("touchstart", function (e){ startX = e.touches[0].pageX; startY = e.touches[0].pageY; }); //获取点击结束后的坐标 el.addEventListener("touchend", function(e){ endX = e.changedTouches[0].pageX; endY = e.changedTouches[0].pageY; var x = Math.abs(endX - startX); var y = Math.abs(endY - startY); //长方形的斜边长 = 两个直线的平方的和的平方根 moveLength = Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2)); alert("本次的移动距离为:"+moveLength); }) })(); ~~~