javascript
を使ってアニメーションしました。単一のボールの形を使用すると、ページの上部に移動します。誰もがクローンのような複数のボールを作成する方法役立つだろう..私はただ、次の作業をしたい...JavaScriptを使用したボールアニメーション
- 複数のボールとアニメーション(下から上に)
- 各ボールの位置(のみ左位置)ランダムです。
- 無限プロセス。
javascript
で実現できますか?事前:)
.circle{
width: 50px;
height: 50px;
border-radius: 30px;
position: absolute;
bottom: -60px;
left: 2px;
transition: 0.1s;
}
body{
overflow: hidden;
position: relative;
background: violet
}
#box{
width: 100%;
height: 100%;
}
<body>
<div id="box"></div>
<script type="text/javascript">
var colors = ['red', 'yellow', 'blue', 'green', 'brown', 'violet'];
var windowHeight = 0;
var parendElement;
window.onload = function() {
parendElement = document.getElementById("box");
windowHeight = window.innerHeight;
document.body.style.height = windowHeight + "px";
console.log(document.body.style.height);
generateBall();
};
function generateBall() {
var leftPos = Math.floor((Math.random() * window.innerWidth) - 30);
var para = document.createElement("p");
para.setAttribute("class", 'circle');
para.style.background = colors[Math.floor(Math.random() * colors.length)];
para.style.left = leftPos + "px";
parendElement.appendChild(para);
var btmPos = 0;
var animationInterval = setInterval(function() {
if (btmPos < windowHeight) {
btmPos += 5;
} else {
console.log("yes");
clearInterval(animationInterval);
parendElement.removeChild(para);
}
para.style.bottom = btmPos + "px";
para.style.left = leftPos + "px";
}, 100);
}
</script>
</body>
を、あなたは何を試してみましたか?どこから始めたらいいかわからない場合は、その事柄についてあなたの思考プロセスを列記してください。 –
私は何を試したのか投稿しました。今私は複数のボールのためにランダムに(左)の位置を設定するために苦労している.. –