It looks like you're trying to mimic the Apple iPhone website: http://www.apple.com/iphone/ . I emulated this method here:
http://jsfiddle.net/Yw9SK/2/ (uses Webkit transitions)
It really does not require a lot of math, do not overdo it. You just need to undo the rotation of the child <div> element and adjust its width / height and offset from the <div> container.
Here's how to do it:
container width: 500 height: 500 rotation: 0 top: 0 left: 0 child width: 90 height: 90 rotation: 120deg top: 330 left: 0
To ensure proper rotation, the container must receive a negative rotation of the child:
child rotation: 120deg --> container rotation: -120deg
To have a child center in the view, we need to subtract its width from the width of the container, divide by 2 (to keep it centered), and then subtract any offsets. The same thing happens for height:
Width Height 500 (container width) 500 (container height) - 60 (child width) - 40 (child height)
Since the “stage” is in the center of the top of the container, the new transformation will also be centered inside the scene. (This is not much harder to do for a rectangle compared to a square.) Thus, our transformation, which should be applied to the <div> container, is:
transform: rotate(-120eg) translateX(220px) translateY(-100px)
Rinse and repeat for the remaining children and go through them accordingly.
This JSFiddle is just an example of how to do this. This is not a very well-designed implantation. A better solution would be to delay the transition or delay the animation (instead of setInterval), and then listen for the events of 'transitionEnd' or 'animationEnd'.
I would definitely recommend NOT trying to calculate new positions and rotations programmatically on the fly (although you can, and then you just need to get these values from the .style property in JS). I would recommend that the translations / rotations be predefined for you in advance (as can be seen from my example, although they should be in CSS) and just apply them in the correct order to the container. This will ensure a quick and smooth transition.
skyline3000
source share