I cannot read a CSS3 transform rotate value in:
- Opera 9.62
- Opera 10.51
- FireFox 4.01
Works fine in IE, Chrome and Safari, but not in these three above.
Here is the source:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.6.1.min.js"></script>
<style>
div {
-webkit-transform: rotate(-5deg);
-moz-transform: rotate(-5deg);
-o-transform: rotate(-5deg);
-ms-transform: rotate(-5deg);
transform: rotate(-5deg);
border: 1px solid black;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
// tries to read the CSS rotate data
// starts by reading -webkit-transform, if it
// fails then read -moz-transform and so on
var getRotation = function ($e) {
var value = $e.css('-webkit-transform');
if (value === undefined) {
value = $e.css('-moz-transform');
if (value === undefined) {
value = $e.css('-o-transform');
if (value === undefined) {
value = $e.css('-ms-transform');
if (value === undefined) {
value = $e.css('transform');
}
}
}
}
return value === undefined? '' : value;
};
var returnValue = getRotation($("div"));
alert(returnValue === ''?
"Failed to get rotation info!" :
"Got it: " + returnValue);
});
</script>
</head>
<body>
<div>rotated</div>
</body>
</html>
So, I want to use jquery css() to read the rotation angle, but strangely, Opera 10.51 and FF 4.01 (and below) cannot read it, although the div is rendered correctly with a rotation effect.
This looks like a jQuery bug or a browser bug. Does anyone have a workaround for Opera/FF?
If you get an alert saying “Got it” then it works.
Thanks for the help.
Ok, I figured out the problem. The problem was on my code, that was not checking properly the return values from the
css()getter.Before I had:
The problem was fixed, by changing the above condition to:
where
notDefinedis the functionTo be cross browser, I need to compare against all these 3 cases, not only undefined.
You can see the update here
It works for all the latest versions of IE (also IE7 and 8), Firefox, Safari, Chrome and Opera.