Generally speaking, CSS transitions (and most of CSS, really) were designed with progressive enhancement in mind. The intended fallback in browsers that don't understand transitions is quite simply to ignore the transition properties themselves. This allows the style changes to still take place, only immediately and not in a smooth transition (as implied by the name), and obviates the need for complex workarounds.
What you're looking to do however is to not have any change in state occur at all; you want your image to be fixed in the unzoomed state. That will take a bit more work.
If @supports
had been implemented in the beginning, you could easily get away with
img{
display:block;
position:absolute;
height:auto;
width:100%;
top:0;
left:0;
-webkit-transition-property: width, left, top;
-webkit-transition-duration: .8s;
-webkit-transition-timing-function: ease-out;
transition-property: width, left, top;
transition-duration: .8s;
transition-timing-function: ease-out;
}
@supports (-webkit-transition-property: all) or (transition-property: all) {
div:not(:hover) img{
width:200%;
left:-30%;
top:-60%;
}
}
But of course, not everything works that way. It's a real shame that @supports
was proposed so late and implementations still haven't caught on. But I digress.
Looking at the support tables at caniuse.com, it looks like Gecko- and WebKit/Blink-based browsers are extremely well covered (except maybe Firefox 3.6 and older), which is a relief because I can't think of any pure CSS-based solution to cater to those engines (other than ugly hacks).
For other browsers, I can see some other workarounds:
It may be worth including the -o-
prefix if you care about Presto Opera.
Likewise with -moz-
if you care about Firefox < 16.
For IE, simply hiding the div:not(:hover) img
rules in conditional comments is enough, since the first version of IE to support transitions and ignore conditional statements happens to be the same — version 10:
<!--[if !IE]><!-->
<style>
div:not(:hover) img{
width:200%;
left:-30%;
top:-60%;
}
</style>
<!--<![endif]-->
Note the use of div:not(:hover)
here, analogous to the hypothetical @supports
example above. You will need to swap the declarations with your img
rule accordingly.