jquery - 停止 svg 动画

标签 jquery css svg

我想通过 Jquery 停止 svg。 svg 图像通过 viewHelper(如 Typo3Fluid)直接放入 DOM。 如果我添加一个 .stopanimation-play-state: paused; 它不会暂停 svg。

JS:

    var bulletlist = function (container) {
    var self = this;
    this.container = container;

    $(".x-control", self.container).click(function() {
        //remove & show button
        $(".x-control").toggleClass("x-play");

        //start and stop svg
        $(".wv_bulletlist svg").toggleClass("stop");
        //$(".wv_bulletlist svg").css("animation-play-state", "paused");

        return false;
    });
};

$(function () {
    $('.wv_bulletlist').each(function () {
        new bulletlist(this);
    });
});

CSS:

<style>path {
  stroke-dasharray: 125;
  stroke-dashoffset: 0;
  animation: dash 4s .01s linear forwards infinite;
}
#t-horizontal, #t-vertical {
  stroke-dasharray: 30;
  stroke-dashoffset: 0;
  animation-name: dash-short;
}
#t, #t-horizontal, #t-vertical {
  animation-delay: .5s;
}
#s {
  animation-delay: 1s;
}
@keyframes dash-short {
  from, 30% {
    stroke-dashoffset: 30;
  }
  76%, to {
    stroke-dashoffset: 0;
  }
}
@keyframes dash {
  from {
    stroke-dashoffset: 125;
  }
  67%, to {
    stroke-dashoffset: 0;
  }
}</style>

所有这些都必须与 IE 11 兼容,我无法事先知道将什么 svg 放在那里。 将不胜感激任何提示或建议。

亲切的问候

最佳答案

动画附在一个或多个<path>元素,你的 stop使用选择器 ".wv_bulletlist svg" 在元素上设置类. CSS 动画属性是不可继承的。您必须设置 animation-play-state: paused在具有运行动画的相同路径元素上。

关于jquery - 停止 svg 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52483182/

相关文章:

javascript - 滚动时如何使我的顶部菜单保持固定

javascript - D3 将 x 轴标签定位在矩形内并旋转 90 度

javascript - 单击链接时,关注 svg 元素

javascript - Soundcloud 播放器小部件在轨道更改时触发事件

javascript - 从隐藏的复选框中获取值(value)

javascript - 如何让这种玻璃 splinter 效果适用于多个 div?

javascript - 使用鼠标滚轮和按钮循环水平滚动两个 div

html - 将可滚动表格列与CSS中的标题对齐

html - Internet Explorer 9 中的 SVG 打印

css - 默认打开切换