You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.1 KiB
56 lines
1.1 KiB
10 years ago
|
var mouse = {
|
||
|
x: 0,
|
||
|
y: 0,
|
||
|
direction:0,
|
||
|
|
||
|
start: {
|
||
|
x:0,
|
||
|
y:0
|
||
|
},
|
||
|
|
||
|
dragging: false,
|
||
|
|
||
|
set: function (x,y) {
|
||
|
mouse.x = x
|
||
|
mouse.y = y
|
||
|
mouse.direction = Math.atan2(y-mouse.start.y,x-mouse.start.x)
|
||
|
},
|
||
|
|
||
|
coords: function (e) {
|
||
|
// e.preventDefault();
|
||
|
if(e.pageX){
|
||
|
mouse.set(e.pageX,e.pageY)
|
||
|
}
|
||
|
else if(e.offsetX) {
|
||
|
mouse.set(e.offsetX,e.offsetY)
|
||
|
}
|
||
|
else if(e.layerX) {
|
||
|
mouse.set(e.layerX,e.layerY)
|
||
|
}
|
||
|
else if(e.targetTouches && e.targetTouches.length > 0){
|
||
|
mouse.set(e.targetTouches[0].pageX,e.targetTouches[0].pageY)
|
||
|
}
|
||
|
},
|
||
|
|
||
|
down: function (e) {
|
||
|
mouse.coords(e)
|
||
|
mouse.start.x=mouse.x
|
||
|
mouse.start.y=mouse.y
|
||
|
mouse.dragging = true
|
||
|
// console.log(e)
|
||
|
|
||
|
},
|
||
|
|
||
|
up: function (e) {
|
||
|
mouse.coords(e)
|
||
|
mouse.dragging = false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
document.addEventListener("touchstart", mouse.down, true);
|
||
|
document.addEventListener("touchend", mouse.up, true);
|
||
|
document.addEventListener("touchmove", mouse.coords, true);
|
||
|
|
||
|
document.addEventListener("mousedown", mouse.down, true);
|
||
|
document.addEventListener("mouseup", mouse.up, true);
|
||
|
document.addEventListener("mousemove", mouse.coords, true);
|