Created
October 14, 2016 18:14
-
-
Save AndrePessoa/0d2537f71d2be6673a0541cfa939937a to your computer and use it in GitHub Desktop.
SVG jquery rotation
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
function rotate( $el, start, end, time ){ | |
var bb = $el[0].getBBox(); | |
var center = { | |
x: ( bb.width ) / 2 + bb.x, | |
y: ( bb.height ) / 2 + bb.y, | |
}; | |
$({ | |
r: start | |
}).animate({ | |
r: end | |
},{ | |
duration: time || 1000, | |
step: function( now, fx ) { | |
var data = fx.elem.id + " " + fx.prop + ": " + now; | |
$el.attr("transform", "rotate(" + now.toPrecision(3) +" "+ center.x.toPrecision(3) +" "+ center.y.toPrecision(3) +")" ); | |
} | |
}); | |
} | |
var animated = false; | |
$('svg').click(function () { | |
if( animated ) return false; | |
animated = true; | |
$(this).attr("class", "animar"); | |
$(".circulo").each(function(){ | |
rotate( $( this ), 0 , -45, 1000 ); | |
}); | |
rotate( $( "#estrutura" ), 0 , 45, 1000 ); | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment