是否可以在CSS中随机化动画

下面的动画在三个不同的元素上运行。

下面的动画在三个不同的元素上运行。

我怎么能随机化动画,使它们发生在不同的时间?

@keyframes shine{
  10% {
    opacity: 1;
    top: -30%;
    left: -30%;
    transition-property: left, top, opacity;
    transition-duration: 0.7s, 0.7s, 0.15s;
    transition-timing-function: ease;
  }
  100% {
    opacity: 0;
    top: -30%;
    left: -30%;
    transition-property: left, top, opacity;
  }
}
http://jsfiddle.net/nqQc7/1186/

另外,动画之间似乎存在延迟,如何在不增加过渡本身速度的情况下加快动画之间的持续时间?

我已经尝试添加更多的关键帧,但它似乎并没有增加动画之间的时间。

1

您可以为每个按钮使用不同的动画延迟和动画持续时间值,如下所示:

/**
 * Icon
 */
.icon {
  position: relative;
  overflow: hidden;
  width: 50px;
  height: 50px;
  display: inline-block;
  
  margin: 25px 0 25px 25px;
  border-radius: 5px;
  color: #fff;
  text-decoration: none;
  text-align: center;
  line-height: 50px;
  font-size: 12px;
  font-family: sans-serif;
}
.icon:nth-child(1) { background: cornflowerblue; }
.icon:nth-child(2) { background: salmon; }
.icon:nth-child(3) { background: gray; }
/**
 * The "shine" element
 */
.icon:after {
  
  animation: shine 1s ease-in-out alternate infinite;
  animation-fill-mode: forwards;  
  content: "";
  position: absolute;
  top: -110%;
  left: -210%;
  width: 200%;
  height: 200%;
  transform: rotate(30deg);
  
  background: rgba(255, 255, 255, 0.13);
  background: linear-gradient(
    to right, 
    rgba(255, 255, 255, 0.13) 0%,
    rgba(255, 255, 255, 0.13) 77%,
    rgba(255, 255, 255, 0.5) 92%,
    rgba(255, 255, 255, 0.0) 100%
  );
}
.icon:nth-child(1):after { animation-delay: .1s; }
.icon:nth-child(2):after { animation-delay: .3s; }
.icon:nth-child(3):after { animation-delay: .5s; }
/* Hover state - trigger effect */
/* Active state */
@keyframes shine{
  60% {
    top: -30%;
    left: -30%;
  }
  100% {
    opacity: 0;
    top: -30%;
    left: -30%;
  }
}
<a href="#" cl="icon">let</a>
<a href="#" cl="icon">it</a>
<a href="#" cl="icon">shine</a>
<!--
Forked by:
Nicolas Gallagher - http://jsfiddle.net/KbNq7/
Chris Coyier - http://jsfiddle.net/chriscoyier/hk6z9/1/
-->

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(580)
在iOS上共享指向InstagramDirectMessage的链接 /文本
上一篇
DynamicsCRM2013:工作流设计器布尔值和Optionset字段设置值消失
下一篇

相关推荐

  • css的边框:Welcome!

    示例示例CSS边框是指在HTML元素上添加边框的一种样式。它可以使元素看起来更加突出,并且可以用来控制元素的外观和布局。CSS边框有四种属性:border-style,border-width,border-color和border-radius。…

    2023-01-19 01:24:45
    0 70 64
  • css选择器nthchild:The nth-child Selector

    CSS 选择器 nth-child 是一种 CSS 伪类选择器,可以用来匹配特定的元素。它可以用来选择父元素的第 n 个子元素。…

    2023-01-12 14:18:15
    0 29 66
  • css文字省略号探索未知的世界

    CSS文字省略号是指在文本过长时,超出指定宽度的部分用省略号代替,可以使用CSS的text-overflow属性来实现,下面是一个示例代码:…

    2023-02-15 02:17:08
    0 13 21
  • css 公共样式:标题

    示例示例CSS公共样式是指在页面中,多个元素共享的样式,可以减少代码重复,提高代码的可维护性。例如:…

    2023-02-04 15:29:26
    0 75 47
  • css宋体代码:标题

    示例示例CSS宋体代码是指将文本的字体设置为宋体,以下是一个CSS宋体代码的示例:上述代码将文本字体设置为宋体,如果浏览器不支持宋体,则会使用默认的sans-serif字体。…

    2023-03-19 06:31:00
    0 39 44
  • css 盒子居中:标题

    使用margin属性实现:使用flex布局实现:…

    2023-02-19 08:23:05
    0 78 84
  • css有几种引入方式## 五种CSS引入方式

    示例示例CSS有三种引入方式:外部引用:…

    2023-01-11 05:01:16
    0 34 74
  • css table属性:行 Name Age Gender

    示例示例CSS table属性是用来控制表格的外观和布局的CSS属性,它们可以让表格更加灵活,更容易控制。下面是一些常用的CSS table属性:…

    2023-02-18 03:17:09
    0 92 24

发表评论

登录 后才能评论

评论列表(23条)