目前,我有这样的代码:

@-webkit-keyframes blinker {
  from { opacity: 1.0; }
  to { opacity: 0.0; }
}

.waitingForConnection {
  -webkit-animation-name: blinker;
  -webkit-animation-iteration-count: infinite;
  -webkit-animation-timing-function: cubic-bezier(.5, 0, 1, 1);
  -webkit-animation-duration: 1.7s;
}

它会眨,但只会“朝一个方向”眨。我的意思是,它只是淡出,然后它以不透明度:1.0再次出现,然后再次淡出,再次出现,如此循环……

我想让它淡出,然后从这个淡出再次“提升”到不透明度:1.0。这可能吗?


当前回答

.neon {
  font-size: 20px;
  color: #fff;
  text-shadow: 0 0 8px yellow;
  animation: blinker 6s;
  animation-iteration-count: 1;
}
@keyframes blinker {
  0% {
    opacity: 0.2;
  }
  19% {
    opacity: 0.2;
  }
  20% {
    opacity: 1;
  }
  21% {
    opacity: 1;
  }
  22% {
    opacity: 0.2;
  }
  23% {
    opacity: 0.2;
  }
  36% {
    opacity: 0.2;
  }
  40% {
    opacity: 1;
  }
  41% {
    opacity: 0;
  }
  42% {
    opacity: 1;
  }
  43% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
  100% {
    opacity: 1;
  }
}

我使用font-family: "Quicksand", sans-serif;

这是对字体的导入(放到style。css的顶部)

@import url("https://fonts.googleapis.com/css2?family=Quicksand:wght@300&display=swap");

其他回答

改变持续时间和不透明度以适应。

.blink_text { 
    -webkit-animation-name: blinker;
    -webkit-animation-duration: 3s;
    -webkit-animation-timing-function: linear;
    -webkit-animation-iteration-count: infinite;
    -moz-animation-name: blinker;
    -moz-animation-duration: 3s;
    -moz-animation-timing-function: linear;
    -moz-animation-iteration-count: infinite;
    animation-name: blinker;
    animation-duration: 3s;
    animation-timing-function: linear; 
    animation-iteration-count: infinite; color: red; 
} 

@-moz-keyframes blinker {
    0% { opacity: 1.0; }
    50% { opacity: 0.3; }
    100% { opacity: 1.0; } 
}

@-webkit-keyframes blinker { 
    0% { opacity: 1.0; }
    50% { opacity: 0.3; }
    100% { opacity: 1.0; } 
} 

@keyframes blinker { 
    0% { opacity: 1.0; } 
    50% { opacity: 0.3; } 
    100% { opacity: 1.0; } 
}

如果你想要平滑的动画,试试这个。

    .blink {
        animation: blinker 1s infinite;
    }
      
    @keyframes blinker {
        from { opacity: 1.0; }
        50% { opacity: 0.5; }
        to { opacity: 1.0; }
    }
    <span class="blink">I am blinking</span>

我不知道为什么,但动画只有可见性属性是不工作在任何浏览器。

你能做的就是使不透明属性动画化,这样浏览器就没有足够的帧来淡入或淡出文本。

例子:

跨度{ 透明度:0; 动画:眨眼1s线性无限; } @关键帧闪烁{ 从, 49.9% { 透明度:0; } 50%, , { 透明度:1; } } 我正在闪烁文本</span>

这是每个人的好榜样。试一试

.blinking_live {
    height: 15px;
    width: 15px;
    border-radius: 15px;
    background: #58C03D;
    animation: blink-live 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}

@keyframes blink-live{

    0% { opacity: 1.0; }
    50% { opacity: 0.0; }
    100% { opacity: 1.0; }
}


<div class="blinking_live"></div>

晚了,但想添加一个新的与更多的关键帧…下面是CodePen上的一个例子,因为内置代码段有一个问题:

.block{ display:inline-block; padding:30px 50px; background:#000; } .flash-me { color:#fff; font-size:40px; -webkit-animation: flash linear 1.7s infinite; animation: flash linear 1.7s infinite; } @-webkit-keyframes flash { 0% { opacity: 0; } 80% { opacity: 1; color:#fff; } 83% { opacity: 0; color:#fff; } 86% { opacity: 1; color:#fff;} 89% { opacity: 0} 92% { opacity: 1; color:#fff;} 95% { opacity: 0; color:#fff;} 100% { opacity: 1; color:#fff;} } @keyframes flash { 0% { opacity: 0; } 80% { opacity: 1; color:#fff; } 83% { opacity: 0; color:#fff; } 86% { opacity: 1; color:#fff;} 89% { opacity: 0} 92% { opacity: 1; color:#fff;} 95% { opacity: 0; color:#fff;} 100% { opacity: 1; color:#fff;} } <span class="block"> <span class="flash-me">Flash Me Hard</span> </span>