如何为参照SVG背景制作动画

时间:2018-08-31 15:31:58

标签: javascript jquery css svg vivus

是否存在使用vivus.js对参照背景svg进行动画处理的方法?我正在尝试使用它。我在官方文档中找到了此代码,但我不知道这是否可行。看下面的代码:

HTML
<section id="svg-bg" class="materiais-topo">
  <!-- some elements here -->
</section>

CSS (SASS)
    .materiais-topo {
      background-color: $green-fluo;
      background-image: url('../images/line-fluo.svg');
      background-position: center center;
      background-repeat: no-repeat;
    }

JS
new Vivus-bg('svg-bg', {
   file: MAIN_URL+'dist/images/line-fluo.svg'
});

有人有什么解决办法吗?如果您知道要在没有vivus.js的情况下为参照背景svg制作动画,请告诉我。

编辑:此方法仅将SVG文件插入到我的div元素中。

1 个答案:

答案 0 :(得分:1)

据我所知,用Javascript操作Background SVG是不可能的。

但是,您可以:

以下是SVG SMIL动画的示例:

<svg xmlns="http://www.w3.org/2000/svg" width="300px" height="100px">
    <rect x="0" y="0" width="300" height="100" stroke="black" stroke-width="1" />
    <circle cx="0" cy="50" r="15" fill="blue" stroke="black" stroke-width="1">
        <animateMotion path="M 0 0 H 300 Z" dur="3s" repeatCount="indefinite" />
    </circle>
</svg>
相关问题