开发者

JavaScript executes for a computer but not for a iPad

JavaScript executes for a computer but not for a iPad. I am not sure if there is another gesture. But when I touch and drag an item on the Browser it should move, it does on the computer, but it moves the whole screen on the iPad. Do I need to rewrite gestures in JavaScript... and how?

None of the gestures seem to be working the way they do on the computer for the 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;


This happens because the iPad/iPod Touch/iPhone/etc is a touch interface to start with. To navigate a large page you need to be able to touch and drag the screen around. vonconrad has a great explanation about this issue here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜