Javascript一次对两种效果进行样式化

javascript styling two effects at once

本文关键字:样式 两种 一次 Javascript      更新时间:2023-09-26

你好,我有一堆动态创建的div框与iddiv1-div999。然后我抓取随机的盒子,并将动画名称更改为"grow"。我还想将播放状态更改为"running",但现在我只是随机选择另一组来更改播放状态。

else if (e.keyCode == '40') {
                 for(var i = 0;i <400; i++){
                     document.getElementById("div"+Math.floor((Math.random()*1000) + 1 )).style.animationName = "Grow";
                     document.getElementById("div"+Math.floor((Math.random()*1000) + 1 )).style.animationPlayState = "running";
                }
            }

我想更改一个组选择的动画名称和播放状态。比如:

document.getElementById("div"+Math.floor((Math.random()*1000) + 1 )).style.animationName = "Grow" / style.animationPlayState = "running";

有什么办法可以做到吗?

谢谢!

如何将div ID的随机组存储在数组中?希望对你有帮助。

else if (e.keyCode == '40') {
                 for(var i = 0;i <400; i++){
var randomSelection=[]; //a new array to store all ID's
randomSelection[i]=Math.floor((Math.random()*1000) + 1))
document.getElementById("div"+randomSelection[i].style.animationName = "Grow";
document.getElementById("div"+randomSelection[i].style.animationPlayState = "running";
                }
            }