Last active
August 29, 2015 14:06
-
-
Save enesser/864664faf5a861e63e46 to your computer and use it in GitHub Desktop.
Animating an SVG via scale using animateTransform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// animating an SVG via scale using transform child without using any frameworks | |
// compatible with IE9. | |
// write out an SVG-compatible XML tag, not easy to do in jQuery | |
function makeSVG(tag, attrs) { | |
var el= document.createElementNS('http://www.w3.org/2000/svg', tag); | |
for (var k in attrs) | |
el.setAttribute(k, attrs[k]); | |
return el; | |
} | |
// an example of an animated transform using scale | |
var scale = makeSVG('animateTransform', { | |
attributeName: 'transform', | |
attributeType: 'XML', | |
type: 'scale', | |
begin: '0s', | |
dur: '4s', | |
values: '1 1; 1.5 1.5', | |
fill: 'freeze', | |
repeatCount: 'indefinite' | |
}); | |
//add transform animation to the child of a path element in an SVG | |
document.getElementById('someElement').appendChild(scale); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment