html - CSS 动画循环淡入淡出 1-2-3-1-2-3-1-2

标签 html css

我有带关键帧的文本过渡,有 3 个标题,它们会一个接一个地淡入和淡出它工作正常但我希望它在所有三个关键帧完成后再次回到一个

它应该在所有 child 完成后无限工作

动画序列

1-2-3-1-2....等等

CSS:

h2 {
  position: absolute;

  opacity: 0;
  -webkit-animation: fadeOut 3s ease-out forwards;
  animation: fadeOut 3s ease-out forwards;
}

@-webkit-keyframes fadeOut {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}
@keyframes fadeOut {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

h2:nth-child(1) {animation-delay: 0s;}
h2:nth-child(2) {animation-delay: 3s;}
h2:nth-child(3) {animation-delay: 6s;}

这是 HTML :

<h2>Hello Heading 1</h2>
<h2>Heading 2</h2>
<h2>Heading 3</h2>

JSFiddle : https://jsfiddle.net/Lq4w007u/

最佳答案

使用此代码

setInterval(function(){ 
    var x = 0;
    for(var i=1; i<=3; i++){
      $("h2:nth-child(i)").css("animation-delay", "x.'s'");

      x = x+3;
    }

$("h2").css({
"animation": "fadeOut",
"animation-duration": "3s",
"animation-timing-function": "ease-out"
})

}, 12000);

关于html - CSS 动画循环淡入淡出 1-2-3-1-2-3-1-2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44350842/

相关文章:

javascript - 如何在javascript中按值删除/隐藏动态单选按钮

html - 在有/没有滚动条的页面之间切换时停止背景移动?

javascript - 避免克隆 HTMLTemplate 来检索 innerHTML?

html - 属性选择器覆盖多个元素的类

jquery - 相对于页面上的元素将 div 滑出

css - Bootstrap 导航栏 - 灰度主题

javascript - 检查一个类是否存在于 JavaScript 中表格的任何行中

html - 样式化 HTML5 数据列表

html - CSS 文本叠加在完整图像上

html - HTML 中 <a> 标签上的文本垂直居中