html - 向具有事件状态的元素添加动画

标签 html css css-animations

对于我的网络作业,我得到了针对网页特定部分的以下说明:

There are five dice in play. When the webpage is loaded, a three-dimensional image must be displayed for each dice. When the dice is clicked, it should display a rolling animation and then it shows a particular dice face (the results of the roll). This value must only be visible when the dice is clicked (active). As an example if you clicked on the dice you might see a dice face showing 5 pips demonstrating that you “rolled” a 5.

我不确定当动画处于事件状态时如何将动画作为图像的一部分。到目前为止,这是我的页面的照片。骰子必须显示动画。

dice game

最佳答案

您还可以将 GIF 图像设置为背景图像以添加动画。 但这里有一个有效的 CSS 动画示例:

.dices {
  width: 204px;
  height: 120px;
  border: 1px solid black;
  list-style: none;
  padding: 0px 10px;
}

.dice {
  display: inline-block;
  width: 80px;
  height: 80px;
  background: black;
  margin: 20px 10px;
  transition: background 1s;
  transition: transform 2s;
  -webkit-transition: -webkit-transform 2s;
}

.dice:active {
  background: yellow;
  transform: rotate(720deg);
  -webkit-transform: rotate(720deg);
}
<ul class="dices">
  <li class="dice"></li>
  <li class="dice"></li>
</ul>

关于html - 向具有事件状态的元素添加动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33788720/

相关文章:

javascript - 如何在没有特定子元素的情况下获取div中的内容

css - 无限 CSS3 动画闪烁

html - 文字在某些电子阅读器应用程序上不合理,但在其他应用程序上会

javascript - 我们如何在 css 中为具有特殊字符的单词设置样式?

html - 垂直对齐单元格中的文本

html - 防止长单元格内容拉伸(stretch)单元格

css - 动画内联元素滚动全宽

CSS 动画在 IE11 和 Edge 中不起作用

html - 如何使用 css 赋予自定义形状边框效果

javascript - 如何关闭覆盖屏幕的div