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";
}
}