是否可以在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="#" class="icon">let</a>
<a href="#" class="icon">it</a>
<a href="#" class="icon">shine</a>
<!--
Forked by:
Nicolas Gallagher - http://jsfiddle.net/KbNq7/
Chris Coyier - http://jsfiddle.net/chriscoyier/hk6z9/1/
-->

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

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

相关推荐

  • css设置滚动条宽度设置:This is a title

    CSS设置滚动条宽度的方法:使用CSS3的。-webkit-属性:…

    2023-06-06 10:53:01
    0 16 65
  • css超出隐藏省略:爱上海,一个充满活力的城市!

    css超出隐藏省略,可以使用CSS的text-属性来实现,具体代码如下:…

    2023-06-26 11:29:04
    0 14 73
  • css怎么让图片居中显示:使用CSS实现图片居中显示

    示例示例可以使用CSS的margin属性来实现图片居中显示,代码示例如下:上面的代码中,我们使用了 `margin: 0 auto;` 来让图片居中显示,其中`0`表示上下边距,`auto`表示左右边距自动调整,这样就可以让图片居中显示。…

    2023-06-26 00:45:20
    0 26 37
  • css 背景铺满:欢迎来到我的世界

    CSS 代码如下:上面的代码可以使背景图片填充整个浏览器窗口,并且保持图片的原始比例。…

    2023-10-11 10:49:49
    0 73 71
  • css 子样式:标题

    CSS 子样式是指在父样式的基础上,对其子元素进行单独定义的样式。它可以使用类选择器、ID 选择器或者属性选择器来定义,如下所示:…

    2023-04-13 14:42:51
    0 16 35
  • css 间隔:如何利用 CSS 进行间隔调整

    示例示例CSS 间隔是指在 CSS 中使用的间距属性,它可以用来设置元素之间的距离。有几种常用的 CSS 间隔属性,包括:…

    2023-06-05 02:47:09
    0 20 93
  • css导入字体:标题

    示例示例CSS导入字体可以通过@font-face规则来实现,代码示例如下:…

    2023-04-22 12:42:42
    0 51 13
  • cssci与sci的区别比较两者在科学研究中的作用

    CSSCI(中国社会科学引文索引)是中国社会科学院出版社编辑的中国社会科学文献引文索引,收录中国社会科学领域的期刊文献及其他文献,主要收录中国社会科学领域的期刊文献,也收录部分论文集、学位论文及其他文献。…

    2023-11-15 05:05:39
    0 87 80

发表评论

登录 后才能评论

评论列表(46条)