Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

-webkit-transform translate around center

Tags:

css

webkit

For fun Im making a analog clock :D but how to i get it to rotate around center? I want to rotate the thingy showing minutes. its already placed pointing at 15 like in 15.15, 16.15.

doing a plain rotate("10deg") wil rotate it around it self. guessing i have to do something like this:

$("#minPointer").css("-webkit-transform", "translate(-100px, -100px)");
$("#minPointer").css("-webkit-transform", "rotate("+val+"deg)" );
$("#minPointer").css("-webkit-transform", "translate(100px, 100px)" );

the pin is placed center in a 200x200 box. and the above does not work :(

like image 657
Jason94 Avatar asked Jun 23 '11 13:06

Jason94


2 Answers

Use -webkit-transform-origin to set what point transformations occur with respect to:

// Replace percentages to reflect what point you want to rotate around.
// Pixel values are fine.
$("#minPointer").css("-webkit-transform-origin", "50% 100%" );
$("#minPointer").css("-webkit-transform", "rotate("+val+"deg)" );
like image 150
You Avatar answered Nov 22 '22 02:11

You


You need to use the transform-origin property.

Information and examples: https://developer.mozilla.org/En/CSS/-moz-transform-origin

like image 40
thirtydot Avatar answered Nov 22 '22 03:11

thirtydot