heygrady / transform

jQuery 2d transformation plugin
437 stars 87 forks source link

Get transformation parametrs #7

Closed Chizh closed 14 years ago

Chizh commented 14 years ago

$("#elemet").transform({"rotate", 45});

$("#elemet").angle? transformed?

and I need know what real rect of elemt after transformation.

P.S.

sorry may english is bad :)

heygrady commented 14 years ago

This question is unclear.

$("#element").transform({"rotate": 45}); //will rotate the element 45 degrees.

Calculating the dimensions of the transformed object is not directly part of this plug-in but there are useful functions for this bundled into it that you might enjoy. We don't run these on every transformation because it would be wasted calculations in most browsers. IE is the only browser that is utilizing these functions.

var rotate = $.matrix.rotate(45);
var elem = $("#element");
var calc = new $.matrix.calc(rotate, elem.outerHeight(), elem.outerWidth());
var size = calc.size();
alert(size.height);
alert(size.width);

NOTE: When using the height and width related jQuery functions IE will return the transformed height and width instead of the original height and width (which means you don't need to calculate in IE). All other browsers report the expected original width. You can get the original height and width from IE with a function like this:

/**
 * Returns reliable outer dimensions for an object that may have been transformed.
 * @param String dim Height or Width
 * @return Number
 */
function safeOuterLength(dim) {
    var func = 'outer' + (dim.toLowerCase() == 'width' ? 'Width' : 'Height');
    if ($.browser.msie) {
        // TODO: it'd be nice if there were a reliable way to remember this and not have it get stale
        var elem = this.$elem[0];
        // remember the originals
        var style = elem.style.filter;

        // clear the filter
        elem.style.filter = '';

        // pull out the pixel values
        var length = this.$elem[func]();

        // undo our mess
        elem.style.filter = style;

        // Tell the world
        return length;
    }
    return this.$elem[func]();
}
heygrady commented 14 years ago

Closing this issue.