html - 简单的骰子滚动效果 - CSS 动画

标签 html css css-animations

我正在尝试使用 HTML 符号制作简单的掷骰子效果。 我怎样才能重复那个动画?

  1. 我不想使用 JS - 这可能吗?
  2. 我知道我可以将它放在 iframe 元素上并在 6 秒后刷新它等等。

寻找我想念的简单的 css 解决方案。

CSS部分:

.dice { /* HTML symbols */
  font-size: 100px;
  font-weight: 800;
  position: fixed;
  opacity: 0;
}
.dice:nth-child(1n) {animation: rolling 1s linear 1s 1 alternate;}
.dice:nth-child(2n) {animation: rolling 1s linear 2s 1 alternate;}
.dice:nth-child(3n) {animation: rolling 1s linear 3s 1 alternate;}
.dice:nth-child(4n) {animation: rolling 1s linear 4s 1 alternate;}
.dice:nth-child(5n) {animation: rolling 1s linear 5s 1 alternate;}
.dice:nth-child(6n) {animation: rolling 1s linear 6s 1 alternate;}
@-webkit-keyframes rolling {
  0% {opacity: 0;}
  50% {opacity: 1;}
  100% {opacity: 0;}
}

这是 HTML:

<div class="roll">
  <span class="dice">&#9856;</span>
  <span class="dice">&#9857;</span>
  <span class="dice">&#9858;</span>
  <span class="dice">&#9859;</span>
  <span class="dice">&#9860;</span>
  <span class="dice">&#9861;</span>
</div>

最佳答案

.dice { /* HTML symbols */
  font-size: 100px;
  font-weight: 800;
}

.dice::after {
  content:'';
  animation: rolling 6s linear infinite;
}

@keyframes rolling {
  0% {content:'\2680';}
  20% {content:'\2681';}
  40% {content:'\2682';}
  60% {content:'\2683';}
  80% {content:'\2684';}
  100% {content:'\2685';}
}
  <span class="dice"></span>

这对你来说没问题吗?

关于html - 简单的骰子滚动效果 - CSS 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42706560/

相关文章:

javascript - 为什么我的 Space Invaders 不动?

javascript - css网格系统中的模态定位

javascript - 获取 HTML 文档的宽度以随浏览器窗口调整大小

css - 正确旋转动画所需的透视

html - 位置粘性结合 z-index

css - 当我们不能使用字形字体时,如何使用列表的字体大小制作列表样式图像比例?

html - 设置 div 之后的 p 标签的样式(div 不是 p 的父级)

html - css 文本对齐 30%

css - 动画图像到 div vue.js

html - 无法使用 ionic 滚动水平滚动