JavaScript可以在电脑上执行,但不能在iPad上执行

JavaScript executes for a computer but not for a iPad

本文关键字:执行 但不能 iPad 电脑 JavaScript      更新时间:2023-09-26

JavaScript可以在电脑上执行,但不能在iPad上执行。我不确定是否还有其他的手势。但当我在浏览器上触摸并拖动一个项目时,它应该会移动,在电脑上它会移动,但在iPad上它会移动整个屏幕。我是否需要在JavaScript中重写手势…以及如何?

这些手势似乎都不像在iPad电脑上那样好用。

//global variables
var obj,x,y,dx,dy;
// set up draggable elements
function Setup(){
    //exit if the browser doesn't support the DOM
    if (!document.getElementsByTagName) return;
    divs=document.getElementsByTagName("DIV");
    for (i=0; i<divs.length;i++){
        if (divs[i].className != "drag") continue;
        //set event handler for each div with class="drag"
        divs[i].onmousedown=Drag;
    }
}
function Drag(e){
    //Start dragging an object
    if (!e) var e = window.event;
    //which object was clicked?
    obj=(e.target) ? e.target: e.srcElement;
    obj.style.borderColor="red";
    //calculate object offsets from mouse position
    dx=x-obj.offsetLeft;
    dy=y-obj.offsetTop;
}
function Move(e){
    //track mouse movements
    if (!e) var e =window.event;
    if (e.pageX){
        x=e.pageX;
        y=e.pageY;
    }else if (e.clientX){
        x = e.clientX;
        y = e.clientY;
    }else return;
    if (obj){
        obj.style.left=x-dx;
        obj.style.top=y-dy;
    }
}
function Drop(){
    //let go!
    if (!obj) return;
    obj.style.borderColor="black";
    obj=false;
}
//Detect mouse movement
document.onmousemove = Move;
//drop current object on mouse up
document.onmouseup = Drop;
//set up when the page loads
window.onload = Setup;

这是因为iPad/iPod Touch/iPhone等一开始就是触屏界面。要浏览一个大页面,你需要能够触摸和拖动屏幕。Vonconrad对这个问题有很好的解释

相关文章: