【发布时间】:2018-03-26 02:18:34
【问题描述】:
我已经问过这个问题,但它没有解决我的问题 (JavaScript / CSS - How can I start an animation, creating new Divs from cursor position?)。
我找到了一个解决方案,但它似乎无法在 Mozilla 和 Opera 上正常工作。此外,当我多次单击时,div 开始闪烁,这不是我想要的。我需要同时拥有多个 div,因此要同时拥有多个动画。下面是一个现有游戏的示例:http://www.cram.com/flashcards/games/stellar-speller/gre-hit-parade-group-1-320949 请不要使用 jQuery,只需使用普通的 Javascript。谢谢!
<!DOCTYPE html>
<html>
<head>
<style>
#table{
height:300px;
width:900px;
background:red;
}
#ball {
width: 25px;
height: 25px;
position: absolute;
background-color: white;
border-radius:50px;
display:none;
z-index:11;
}
</style>
<script> function animation(){ var elem =
document.getElementById("ball");
document.getElementById("ball").style.display ='block';
document.getElementById("ball").disabled = true;
var x = event.clientX;
var y = event.clientY;
var id = setInterval(frame, 2);
function frame() {
if (x == 900) {
clearInterval(id);
}
else {
x++;
elem.style.top = y + 'px';
elem.style.left = x + 'px';
}
}
}
</script>
</head>
<body>
<div id="table" onclick="animation()">
<div id="ball"></div>
</body>
</html>
【问题讨论】:
-
您应该尝试提出一个独立的问题,而不是要求人们阅读大量背景资料,然后才能尝试帮助您解决具体问题。
标签: javascript css