IOS Android Ipad 多点触摸通用js 库(2)
来源:未知 责任编辑:责任编辑 发表时间:2014-02-02 17:44 点击:次
p>document.getElementsByTagName('head')[0].appendChild(meta);
p>
p>meta = document.createElement('meta');
p>meta.setAttribute('name', 'viewport');
p>meta.setAttribute('content', 'width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;');
p>document.getElementsByTagName('head')[0].appendChild(meta);
p>
p>meta = document.createElement('meta');
p>meta.setAttribute('name', 'viewport');
p>meta.setAttribute('content', 'width=device-width');
p>document.getElementsByTagName('head')[0].appendChild(meta);
p>
p>var TouchType =
p>{
p>Up: 1,
p>Down: 2,
p>Left: 3,
p>Right: 4,
p>Zoom: 5
p>}
p>
p>function documentTouchEvent(event) {
p>//只跟踪一次触摸
p>if (event.touches.length == 1) {
p>switch (event.type) {
p>case "touchstart":
p>event.preventDefault(); //阻止滚动
p>break;
p>case "touchend":
p>event.preventDefault(); //阻止滚动
p>break;
p>case "touchmove":
p>event.preventDefault(); //阻止滚动
p>break;
p>}
p>}
p>}
p>
p>document.addEventListener("touchstart", documentTouchEvent, false);
p>document.addEventListener("touchend", documentTouchEvent, false);
p>document.addEventListener("touchmove", documentTouchEvent, false);
p>
p>//计算两坐标直线距离
p>function CoordinateDistance(x1, y1, x2, y2) {
p>return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
p>}
p>
p>//计算缩放比
p>function Scaling(x1, y1, x2, y2, x3, y3, x4, y4) {
p>return (CoordinateDistance(x2, y2, x4, y4) / CoordinateDistance(x1, y1, x3, y3)).toFixed(2);
p>}
p>
p>function YXMTouch(TouchObjId, MinDelay, LogObjId, IsLog, CallBack) {
p>var minTime = MinDelay;
p>var startTime = 0;
p>var SX = 0;
p>var SY = 0;
p>var EX = 0;
p>var EY = 0;
p>var SX1 = 0;
p>var SY1 = 0;
p>var EX1 = 0;
p>var EY1 = 0;
p>var output = document.getElementById(LogObjId);
p>var isLog = IsLog == null ? false : IsLog;
p>
p>function handleTouchEvent(event) {
p>switch (event.type) {
p>case "touchstart":
p>SX = event.touches[0].clientX;
p>SY = event.touches[0].clientY;
p>if (this.isLog)
p>output.innerHTML = "触摸开始0 (" + SX + "," + SY + ")" + "\n";
p>try {
p>SX1 = event.touches[1].clientX;
p>SY1 = event.touches[1].clientY;
p>if (this.isLog)
p>output.innerHTML = "触摸开始1 (" + SX1 + "," + SY1 + ")" + "\n";
p>}
p>catch (err) { }
p>startTime = event.timeStamp;
p>
p>break;
p>case "touchend":
p>startTime = 0;
p>if (this.isLog)
p>output.innerHTML += "触摸结束 (" + event.changedTouches[0].clientX + "," + event.changeTouches[0].clientY + ")" + "\n";
相关新闻>>
- 发表评论
-
- 最新评论 更多>>