我试图在点击鼠标时消失移动的2D球。而且我想在触摸事件上做同样的事情,如果它在屏幕触摸环境中。问题是球在随机方向上继续移动,我想隐藏我点击的球。
我使用了Javascript,因为我已经提到过,这里是我用来绘制球的代码。 function beginDrawCircle(a,b,color){
clearListeners(instance:Object, eventName:string);
//In your case:
google.maps.event.clearListeners(map, 'idle');
}
我提供了一个额外的信息,我创造了三个这样的球,现在点击它应该消失的任何一个球。
答案 0 :(得分:0)
球是IMG,DIV还是其他标签?如果是这样,为什么不添加一个onclick事件处理程序并将其显示设置为none?
<img src="ball.png" id="ball" onclick="this.style.display='none'"/>
答案 1 :(得分:0)
只需使用:
document.getElementById("ball").onclick = foo;
foo(){
this.style.display = 'none';
}
答案 2 :(得分:0)
由于您没有指定是否使用jQuery或类似的东西,纯Javascript中的解决方案可能是:
//Assuming all the balls are of class ".ball"
var balls = document.querySelectorAll(".ball");
Array.prototype.forEach.call(balls, function(ball){
ball.addEventListener("click", function(event){
ball.style.display = "none";
});
});