0
我試圖複製我的鼠標單擊和滑動操作以在手機或觸摸屏上工作。我想知道是否有人可以幫助我在桌面和移動應用程序上使用此代碼。這裏是我的JavaScript和小提琴: 我試圖做到這一點在普通的JavaScript,而無需使用jquery爲移動應用程序創建鼠標和滑動事件
http://jsfiddle.net/Ltdgx363/2/
obj=document.getElementsByTagName("object");
var mouseDown = 0;
document.onmousedown = function() {
++mouseDown;
}
document.onmouseup = function() {
--mouseDown;
}
var touchDown = 0;
document.touchstart = function() {
++touchDown;
}
document.touchend = function() {
--touchDown;
}
for(i = 0; i < obj.length; i++) {
obj[i].addEventListener("mouseover", colorred ,false);
obj[i].addEventListener("touchmove", colorred ,false);
}
function colorred(){
if(mouseDown>0|touchDown>0){
this.className = "red";
}
}