I have CSS style for a layer:
.element {     -webkit-transform: rotate(7.5deg);          -moz-transform: rotate(7.5deg);           -ms-transform: rotate(7.5deg);            -o-transform: rotate(7.5deg);              transform: rotate(7.5deg); }   Is there a way to get curent rotation value through jQuery?
I tried this
$('.element').css("-moz-transform")   The result is matrix(0.991445, 0.130526, -0.130526, 0.991445, 0px, 0px) which doesn't tell me a lot. What I'm looking to get is 7.5.
Answer: Use the jQuery attr() Method You can simply use the jQuery attr() method to find the data-id attribute of an HTML element.
val() method is primarily used to get the values of form elements such as input , select and textarea . When called on an empty collection, it returns undefined . When the first element in the collection is a select-multiple (i.e., a select element with the multiple attribute set), .
$() = window. jQuery() $()/jQuery() is a selector function that selects DOM elements. Most of the time you will need to start with $() function. It is advisable to use jQuery after DOM is loaded fully.
Here's my solution using jQuery.
This returns a numerical value corresponding to the rotation applied to any HTML element.
function getRotationDegrees(obj) {     var matrix = obj.css("-webkit-transform") ||     obj.css("-moz-transform")    ||     obj.css("-ms-transform")     ||     obj.css("-o-transform")      ||     obj.css("transform");     if(matrix !== 'none') {         var values = matrix.split('(')[1].split(')')[0].split(',');         var a = values[0];         var b = values[1];         var angle = Math.round(Math.atan2(b, a) * (180/Math.PI));     } else { var angle = 0; }     return (angle < 0) ? angle + 360 : angle; }  angle1 = getRotationDegrees($('#myDiv')); angle2 = getRotationDegrees($('.mySpan a:last-child'));   etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With