Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image rotation in IE causes automatic translation. How do I remove the translation?

I'm trying to implement a gauge widget for a website. The spec says only HTML/CSS is allowed, so I can't use JavaScript (don't ask me why -- maybe if there's a really simple way of doing it with JavaScript I could persuade the project lead).

So far I have a div with a background image that shows the back of the gauge. Inside this div is an img that is rotated, depending on the gauge value. This value is dynamically injected into the HTML using PHP.

The gauge works fine in Safari/FireFox, but breaks in IE. If I add a border to the image I can see why -- it appears that the IE rotation also includes an automatic translation so that the needle is off-center (see screenshot below).

So, here's the question: how do I shift the needle back to the center of the gauge in IE?

broken needle rotation in internet explorer

<div style="background: url('genies/gauge.png'); background-repeat: no-repeat; height: 235px; overflow: hidden;">

<img src="genies/gauge-needle.png" 
 style="-moz-transform: rotate(45deg); 
        -o-transform: rotate(45deg); 
        -webkit-transform: rotate(45deg); 
        -ms-transform: rotate(45deg); 
        transform: rotate(45deg); 
        filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.70710678118655, M12=-0.70710678118655,M21=0.70710678118655, M22=0.70710678118655, sizingMethod='auto expand'); zoom: 1;" />

</div>
like image 371
wpearse Avatar asked Nov 05 '22 02:11

wpearse


1 Answers

The problem here is that the image is rotating about a point that you don't expect it to.

You need to set the transform origin to the centre of your image.

For instance, you would use -moz-transform-origin, -webkit-transform-origin, -o-transform-origin, -ms-transform-origin, -etc-transform-origin...

Check out this page for information on how to deal with the Matrix filter in MSIE: https://github.com/heygrady/transform/wiki/correcting-transform-origin-and-translate-in-ie

like image 129
Dancrumb Avatar answered Nov 09 '22 11:11

Dancrumb