ASAIK jquery animate function accepts style properties only. but i want to animate the attributes of an element. consider a SVG element rectangle
<svg>
<rect id="rect1" x=10 y=20 width="100px" height="100px">
</svg>
i want to animate the rectangle element attribute "x" and "y" something like below
$("#rect1").animate({
x: 30,
y: 40
}, 1500 );
but it is not correct way because animate function affects style not attribute of an element.
i knew so many custom plugin is there like raphel.js.
but i don't want to use custom plugin to do this. i want to do this simply in jquery.animate function.
is this possible ?
Thanks,
Siva
just animate the old fashioned way:
you can call
animate
in a jquery like fashion.http://jsfiddle.net/wVv9P/7/
I would try something like this
in the script :
I like the Hoffmann approach, but i think is more elegant without creating a virtual dom object.
This is my coffeescript snippet
which compiles into
Alright all answers here are either specific to SVG or reimplement the .animate() jQuery call, I found a way to use the jQuery call without running into the problem that the attribute gets reset to 0 when the animation starts:
Lets say we want to animate the
width
andheight
attribute of an img tag element with idimage
. To animate it from its current value to 300 we could do this:In this approach we use a div that is not inside the DOM and animate values in it, we then use the div CSS values to animate our element. Not very pretty but gets the job done, if you need to stop the animation you can call
.stop()
on animationDiv.jsfiddle
this may fits you simple