【问题标题】:Which SVG/SMIL DOM element has the `beginElement` method?哪个 SVG/SMIL DOM 元素有 `beginElement` 方法?
【发布时间】:2013-10-10 09:58:50
【问题描述】:

最终这是针对将在 Firefox 中运行的 Kiosk 样式应用程序(使用 jQuery 1.6.4),因此答案可以是特定于 Firefox 的。

我正在尝试制作动画 SVG,但我正在尝试通过动态插入 SMIL 来制作动画。我没有看到任何迹象表明它不能完成,http://satreth.blogspot.ch/2013_01_01_archive.htmlhttp://srufaculty.sru.edu/david.dailey/svg/SMILorJavaScript.svg 似乎都表明它可以完成。

据我了解的问题是我需要调用beginElement 方法来启动动态插入的动画,但我在任何地方都看不到它。

这是一个演示问题的小提琴:http://jsfiddle.net/2pvSX/

未能回答标题中的问题:

  1. 我做错了什么?
  2. 是否有任何资源可用于更好地了解我想要做什么?

这是一个问题:

  1. 我如何定义 SVG?
  2. 我如何创建 SMIL?
  3. 我如何访问 SVG?
  4. 如何插入 SMIL?
  5. 完全不同的东西?

最后,有没有更好的方法来为 SVG 设置动画?

【问题讨论】:

    标签: javascript jquery svg smil svg-animate


    【解决方案1】:

    你需要添加'http://www.w3.org/2000/svg'来创建这样的动画元素

    $(document).ready(function () {
        var svg = $('svg').get(0),
        square = svg.getElementById('red'),
        animation = document.createElementNS('http://www.w3.org/2000/svg', 'animateMotion');
        animation.setAttributeNS(null, 'id', 'walker');
        animation.setAttributeNS(null, 'begin', 'indefinite');
        animation.setAttributeNS(null, 'end', 'indefinite');
        animation.setAttributeNS(null, 'dur', '10s');
        animation.setAttributeNS(null, 'repeatCount', 'indefinite');
        animation.setAttributeNS(null, 'path', 'M 0 0 H 800 Z');
        square.appendChild(animation);
        console.log(animation);
        console.log(typeof animation.beginElement); 
        animation.beginElement();    
    });    
    

    同时删除这一行animation = svg.children[1].children[0].children[1];,这样动画元素就有了beginElement函数
    http://jsfiddle.net/2pvSX/1/

    【讨论】:

    • 为了弄清楚为什么会这样,我需要确保 animateMotion 元素与 SVG 共享相同的命名空间,否则它将不起作用?还是有其他原因?
    • 是的,它需要使用相同的命名空间创建,否则它将与使用 createElement 创建元素相同
    猜你喜欢
    • 2017-07-01
    • 1970-01-01
    • 2014-02-25
    • 2011-07-01
    • 1970-01-01
    • 2013-05-05
    • 2015-04-02
    • 1970-01-01
    相关资源
    最近更新 更多