SVG trigger animation with event

前端 未结 2 1844
礼貌的吻别
礼貌的吻别 2020-11-30 00:37

how do I trigger an svg animate element to begin animating via javascript with an arbitrary event ? I\'m imagining something like begin=\"mySpecialEvent\", then

2条回答
  •  误落风尘
    2020-11-30 01:15

    Start an SVG animation:

    Without javascript, using the "event-value" type of the begin attribute="id.event" (without an "on" prefix) on an animation element; or

    
      
        
      
    
    
    
    

    (W3C 2018, "SVG Animations Level 2, Editor’s Draft", https://svgwg.org/specs/animations/), " Attributes to control the timing of the animation", "begin" attribute, "event-value" value type, https://svgwg.org/specs/animations/#TimingAttributes

    From javascript, by setting an animation element's begin attribute to "indefinite"; and calling beginElement() from script;

    function go () {
      var elements = document.getElementsByTagName("animate");
      for (var i = 0; i < elements.length; i++) {
        elements[i].beginElement();
      }
    }
    
    
      
        
        
      
    
    
    
    

    (W3C 2018, "SVG Animations Level 2, Editor’s Draft", https://svgwg.org/specs/animations/), " Attributes to control the timing of the animation", "begin" attribute, "indefinite" value type, https://svgwg.org/specs/animations/#TimingAttributes

提交回复
热议问题