我正在尝试旋转或变换 div 内的所有元素,但我目前有此功能。它旋转页面上的所有元素。我如何选择要旋转的 div 或类?Array.from(document.all).forEach(o => o.style.transform = "rotate("+ Math.floor(Math.random() * 27 - 12) + "deg)")
最佳答案
您需要使用 document.getElementsByClassName()
或 document.getElementsByTagName()
:
var selected = document.getElementsByClassName('myClass');
Array.from(selected).forEach(o => o.style.transform = "rotate(" + Math.floor(Math.random() * 27 - 12) + "deg)")
关于javascript - 如何选择要应用变换(旋转等)的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44280746/