Skip to content

Instantly share code, notes, and snippets.

@AndrePessoa
Created October 14, 2016 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrePessoa/0d2537f71d2be6673a0541cfa939937a to your computer and use it in GitHub Desktop.
Save AndrePessoa/0d2537f71d2be6673a0541cfa939937a to your computer and use it in GitHub Desktop.
SVG jquery rotation
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