css - SVG 图像 CSS3 动画

标签 css svg css-animations

我需要在无限 CSS3 动画中使气泡聊天的第一个点可见和不可见。

speech buble with dots

为什么我的代码不起作用?

@keyframes onoff {
  0% { display: none; }
  25% { display: block; }
  50% { display: none; }
  100% { display: block; }
}
#circle1 {
  animation: onoff 5s infinite;
}
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240" viewBox="0 0 24 24">
  <g stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" fill="none">
    <path d="M.5 16.5c0 .553.447 1 1 1h2v4l4-4h15c.552 0 1-.447 1-1v-13c0-.553-.448-1-1-1h-21c-.553 0-1 .447-1 1v13z" />


    <!--Annimation on this cicle-->

    <circle id="circle1" cx="8.5" cy="10" r=".5" />

    <!-- -->

    <circle id="circle2" cx="16.5" cy="10" r=".5" />
    <circle id="circle3 " cx="12.5" cy="10" r=".5" />
  </g>
</svg>

最佳答案

display 属性不可设置动画 ( see MDN )。您可以为 opacity 设置动画尽管。

示例:

@keyframes onoff {
  0%, 100% { opacity: 0; }
  50%      { opacity: 1; }
}
#circle1 {
  animation: onoff 2s infinite;
}
<svg xmlns="http://www.w3.org/2000/svg" width="240" height="240" viewBox="0 0 24 24">
  <g stroke="#000" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="10" fill="none">
    <path d="M.5 16.5c0 .553.447 1 1 1h2v4l4-4h15c.552 0 1-.447 1-1v-13c0-.553-.448-1-1-1h-21c-.553 0-1 .447-1 1v13z" />
    <circle id="circle1" cx="8.5" cy="10" r=".5" />
    <circle id="circle2" cx="16.5" cy="10" r=".5" />
    <circle id="circle3 " cx="12.5" cy="10" r=".5" />
  </g>
</svg>

关于css - SVG 图像 CSS3 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33128730/

相关文章:

javascript - Vuejs 添加条件样式格式

javascript - 为什么在 Chrome 中使用 Panzoom 模糊 SVG 元素?

html - 为什么下面的 flexbox 在左边而不是在顶部?

javascript - SVG 清除组<g>

python - Matplotlib:SVG 中不显示点

css - 使用 css3 动画旋转 Div

javascript - Angular 7 动画导致 webkit 浏览器上的 z-index 重叠问题

javascript - CSS 样式转换 vs svg 转换

jquery - 3D Nav CSS3 旋转变换不起作用

html - 同一行上的不同文本样式