Javascript vivus.js-如何按类选择SVG

Javascript vivus.js-如何按类选择SVG,javascript,vivus,Javascript,Vivus,有没有办法按类而不是按ID选择SVG,如下所示: <svg class="mySVG"> <path...> <path...> <path...> </svg> <script> new Vivus('.mySVG', {duration: 200}, myCallback); </script> 新的活体('.mySVG',{duration:200},myCallbac

有没有办法按类而不是按ID选择SVG,如下所示:

<svg class="mySVG">
    <path...>
    <path...>
    <path...>
</svg>

<script>
    new Vivus('.mySVG', {duration: 200}, myCallback);
</script>

新的活体('.mySVG',{duration:200},myCallback);

因为同一类可以有多个元素

  var els= document.getElementsByClassName("mySVG");

  for (var i = els.length - 1; i >= 0; i--) {
    new Vivus(els[i], {duration: 200}, myCallback);
  }

我以前没用过这个库。尽管如此,我还是阅读了文档的来源。我认为你不能使用课堂。根据vivus.js的源代码

* Check and set the element in the instance
* The method will not return anything, but will throw an
* error if the parameter is invalid
*
* @param {DOM|String}   element  SVG Dom element or id of it
*/
Vivus.prototype.setElement = function (element, options) {
// Basic check
if (typeof element === 'undefined') {
throw new Error('Vivus [constructor]: "element" parameter is required');
}

// Set the element
if (element.constructor === String) {
element = document.getElementById(element);
if (!element) {
  throw new Error('Vivus [constructor]: "element" parameter is not related       to an existing ID');
  }
}
如果元素没有ID,它似乎会抛出一个错误

参考:

在这之前,我会尝试用答案实现一些东西,并尝试在它可以接受类的地方实现它


希望这有帮助

谢谢!我不知道如何绕过,我想这是完美的!看这个。再次感谢您抽出时间!
* Check and set the element in the instance
* The method will not return anything, but will throw an
* error if the parameter is invalid
*
* @param {DOM|String}   element  SVG Dom element or id of it
*/
Vivus.prototype.setElement = function (element, options) {
// Basic check
if (typeof element === 'undefined') {
throw new Error('Vivus [constructor]: "element" parameter is required');
}

// Set the element
if (element.constructor === String) {
element = document.getElementById(element);
if (!element) {
  throw new Error('Vivus [constructor]: "element" parameter is not related       to an existing ID');
  }
}