【发布时间】:2021-06-20 20:00:02
【问题描述】:
我创建了一个星夜动画,但想知道是否有人有更好的方法来仅使用 CSS 来“随机”放置 div?另外,我的反应能力也有困难。感谢您的时间!只是想学习。
在http://codepen.io/anon/pen/MeeYWO?editors=1100查看完整代码
#star-bl:nth-of-type(5) {
left: -350px;
top: 225px;
}
#star-bl:nth-of-type(6) {
left: 750px;
top: 250px;
}
#star-bl:nth-of-type(7) {
left: -450px;
}
#star-sm:nth-of-type(8) {
left: -225px;
}
#star-sm:nth-of-type(9) {
left: 500px;
}
#star-sm:nth-of-type(10) {
left: -100px;
}
【问题讨论】:
-
你到底想做什么?
-
寻找一种更简单的方法来对星形位置进行编码,而不是重复 nth-of-type (x) 次数
-
这是一个杂乱无章的沙箱,但它可以工作......使用 JS 和动画侦听器在动画的每次迭代中为“100%”关键帧分配随机值。 codepen.io/ashleedawg/pen/qBBKKeg
标签: html css animation responsive