SVG: Trigger a click event on animateTransform after clicking a button

后端 未结 1 1972
花落未央
花落未央 2021-01-17 04:31

I would like to have my svg animation run when clicking an html button. I thought I could make that work by setting begin=\"click in my animateTransform

1条回答
  •  轮回少年
    2021-01-17 04:54

    If you want to start the animations just do it directly via javascript and the beginElement method, no need for all that click event rigmarole. Note that I've changed the begin on the animation from click to indefinite to make it clearer what's happening.

    var needle = $('#animateNeedle'),
    	tape = $('#animateTape');
    	btn = $('#muhBtn');
    
    btn.on('click', function(){
    	needle[0].beginElement();
    	tape[0].beginElement();
    });
    #tape{
      fill:#ED1C24;
    }
    
    #needle{
      fill:#8DC63F;
    }
    
    
    
    
    
    
        
      
    
      
      
      
    
    

    0 讨论(0)
提交回复
热议问题