heygrady / transform

jQuery 2d transformation plugin
437 stars 87 forks source link

Copy transforms from one element to another #10

Closed Charuru closed 14 years ago

Charuru commented 14 years ago

Is there a way to copy a transform style?

The documentation does not mention a way to get a style.

Thanks.

heygrady commented 14 years ago

Internally we're storing the transformation in a few places.

1) In the end, the transformation is just CSS and it's stored in the style attribute on the element, nothing magic there.

console.log($('#mydiv).transform({rotate: 45}).attr('style')); // -> -moz-transform: rotate(45deg);

2) the transform information as the plug-in understands it is stored in a data-transform attribute on the element.

console.log($('#mydiv).transform({rotate: 45}).attr('data-transform')); // -> rotate(45)

3) The actual transform object is cached on the element itself to speed up animations

console.log($('#mydiv).transform({rotate: 45})[0].transform); // -> [Object]

You could probably do it easiest by copying the data-transform attribute and then applying a transform with preserve.

var attr = $('#mydiv).transform({rotate: 45}).attr('data-transform');
$('#mydiv).attr('data-transform', attr).transform({}, {preserve: true});