If a designer is using a fancy css animation and hopes to have functionality in older and newer browsers, we usually create a #keyframes and a #-webkit-keyframes section. Most of the examples I have seen use both non-prefixed and browser prefixed css under both keyframes, but is this necessary.
#keyframes coolEffect {
-webkit-transform: some value;
transform: some value;
-webkit-animation-timing-function: some value;
animation-timing-function: some value;
}
#-webkit-keyframes coolEffect {
-webkit-transform: some value;
transform: some value;
-webkit-animation-timing-function: some value;
animation-timing-function: some value;
}
Do we need non-prefixed values in the #-webkit-keyframes, since a browser using that would also use -webkit- prefixed css? And likewise since we are using #-webkit-keyframes, do we need to include -webkit- prefixed css in the main #keyframes? Would a simpler smaller version work equally as well?
#keyframes coolEffect {
transform: some value;
animation-timing-function: some value;
}
#-webkit-keyframes coolEffect {
-webkit-transform: some value;
-webkit-animation-timing-function: some value;
}
To clarify, I am not asking about what would work for my particular website, I am asking about functionality and whether or not code sample two would work the same as code sample one.
Thanks.
From my answer to this similar question:
WebKit-based browsers (including Opera 15 and later) still require the -webkit- prefix for animations today, and transforms are only unprefixed in recent versions of Chrome. You will need the prefix for both features.
(Transforms were unprefixed in Chrome 36; animations were not unprefixed until Chrome 43. Both features were unprefixed simultaneously in Safari 9 so you never need to worry about prefixed/unprefixed overlap in Safari.)
In a nutshell, while your two samples don't provide exactly the same functionality, there is no point including any unprefixed properties in #-webkit-keyframes as most WebKit browsers that depend on the prefixed at-rule are never going to need the unprefixed properties. Specifically, from our chat discussion:
You can lose the unprefixed [animation-timing-function] declaration. #keyframes is in the same family as the animation-* properties and no browser in existence supports one unprefixed without the other
As for transforms, only a very fringe few browsers simultaneously support unprefixed transforms and require prefixes on animations. These browsers do still support prefixed transforms, so similarly you can lose unprefixed transforms in #-webkit-keyframes
Note the difference between "support" and "require"
So, code sample two is all you need. It's over 40% smaller than code sample one, with no loss of functionality. 40% is a big deal. The only change I'd make is move the #-webkit-keyframes rule up:
#-webkit-keyframes coolEffect {
-webkit-transform: some value;
-webkit-animation-timing-function: some value;
}
#keyframes coolEffect {
transform: some value;
animation-timing-function: some value;
}
Readers may also be interested in my comments on Autoprefixer:
I assume Autoprefixer sees that Chrome 36-42 supports unprefixed transforms but requires prefixed animations, so it puts transform in #-webkit-keyframes. I don't think that's a good approach. It needlessly doubles the transform declarations. All those versions of Chrome still understand -webkit-transform, so might as well stick to just that
Autoprefixer is good for those who just don't want to have to worry about prefixes or doing all the research needed to really optimize their stylesheets
If you want to optimize your stylesheet, you'll need to do quite a bit of research to find out where prefixes are needed and where they aren't, where unprefixed declarations are needed and where you can leave them out, etc. Prefixes are a pain either way ;)
No. All modern browsers, even going back to IE10, support unprefixed animations.
(source)
Related
I would like to start using the CSS3 filter:opacity() and filter:drop-shadow() properties that are currently under development, as I read that they are hardware accelerated in some browsers on some machines. But at this early point I definitely need a fallback to normal CSS properties like opacity and box-shadow.
Problem is, that the normal CSS fallback strategy of placing new after old fails. Normally new (if supported) would overwrite old. But in this case new and old are completely different properties that will combine! The CSS declaration...
.half-transparent{
opacity: 0.5;
-webkit-filter: opacity(0.5);
filter: opacity(0.5);
}
...will result in a total opacity of 25% instead of 50%.
Example: https://jsfiddle.net/uq4ybvk8/
Is there any way (preferably CSS only) to create a fallback from the new filter properties to well established CSS properties?
The support for filter (with and without prefix) should overlap pretty nicely with support for the Conditional Rules module (#supports), with the exception of older versions of Safari/iOS (before Safari 9). If you treat it as an enhancement (i.e. with a fallback to regular opacity for other browsers), that shouldn't be a big issue. Try something like this, perhaps?
.half-transparent {
opacity: 0.5;
}
#supports ((filter: opacity(0.5)) or (-webkit-filter: opacity(0.5))) {
.half-opacity {
opacity: 1;
-webkit-filter: opacity(0.5);
filter: opacity(0.5);
}
}
Can anyone help me make this Chrome CSS code cross platform? It doesn't work properly in Firefox or at all in IE8. I really appreciate the help, thanks for reading.
.revision-span-in {
opacity: 0;
}
.revision-span:not(.revision-span-out) {
transition: 1s;
-webkit-transition: 1s;
}
.revision-span-out {
position:absolute;
opacity: 0;
}
EDIT - Here is the page with the code suggested below, where the issue persists in Firefox. All text on the page should fade in at intervals, but sometimes random parts are appearing without the fade. If it works fine the first time, try refreshing and you'll see what I mean. The page is an output from Twine, and the modified CSS is right at the bottom. Thanks again.
Example HTML page with inconsistent fade ins in Firefox
You just need to throw some browser vendor-prefixes in there.
Based on the current support of transition, you just need -webkit, -moz, and -o:
.revision-span-in {
opacity: 0;
}
.revision-span:not(.revision-span-out) {
transition: 1s;
-webkit-transition: 1s;
-moz-transition: 1s;
-o-transition: 1s;
}
.revision-span-out {
position:absolute;
opacity: 0;
}
You won't have support in IE9 and lower.
Usually for these experimental features (so in general, if you're not sure about it, look it up) it's best to look up if it's supported by the browser. Since transitions are not completely supported by all major browsers, you need to add the prefix for all browsers that don't fully support it yet. So, according to MDN's Browser support list, and Statcounter's browser usage stats, you should have the following:
.revision-span-in {
opacity: 0;
}
.revision-span:not(.revision-span-out) {
transition: 1s;
-o-transition: 1s;
-webkit-transition: 1s;
}
.revision-span-out {
position:absolute;
opacity: 0;
}
Since both webkit browsers don't have a generally used version that doesn't fully support it without prefix, and firefox doesn't need a prefix, this should work. The problem you're having shows that you've not updated your firefox in a while, and if you're going to test how your site looks in other browsers, I strongly suggest making sure you've got the up-to-date version. Firefox already supports the syntax without -moz- prefix since version 16, and it's at version 26 now (with 25 being the most commonly used at the moment).
Of course if you really want to support even the browsers that almost nobody even uses anymore due to automatic updating (such as Firefox <16), you should indeed like Zach Saucier (deleted his answer) JoshC says also include the -moz- prefix. The -ms- prefix is not needed at all though, since every version of IE that does support transitions also supports it without needing that prefix.
EDIT: added -webkit- for Android/Blackberry default browser.
Extra bit (after seeing added dropbox link)
Considering the dropbox link, what I think is causing it is this: Firefox is still animating the first element when the second shows up, so it doesn't restart the animation.
This could explain why it happens randomly: it only happens when Firefox has a few milliseconds of lag, and firefox continues playing the animation for the second item from the starting point of the second animation. This is likely caused by the fact that your items are nested, so the animation of the first row would be inherited by the animation of the second row, and so forth.
Since your animation length is 0.5 seconds exactly, and the interval between showing elements is also 0.5 seconds exactly, if there is the slightest bit of lag this cause these problems. I suggest putting a tiny extra space between showing each element (perhaps 10 or 50ms or so), or changing the items from a nested method to a sibling method. So, instead of this:
<div class="body content">
<span class="first">500ms
<span class="second">500ms
<span class="third">500ms
<span class="fourth">500ms</span>
</span>
</span>
</span>
</div>
Use this:
<div class="body content">
<span class="first">500ms</span>
<span class="second">500ms</span>
<span class="third">500ms</span>
<span class="fourth">500ms</span>
</div>
So, instead of appending the spans to the current span, append it to the parent element .body.content. I would give you a demo, but your script looks really quite complicated (probably because it's generated by something), so you'll have to try doing that yourself. You could also try putting a tiny bit of extra space between each item's animation starts and see if that fixes it.
Once again I am going to tell you that css3 is still work in progress.So if you want to invoke the css rules then use the vendor prefix provided by their browsers.Note that Internet Explorer 9, and earlier versions, does not support the transition property.
-moz- for firefox use
-webkit- for safari and chrome because both uses the same browser engines
-ms- for microsoft
-o- for opera
.revision-span-in {
opacity: 0;
}
.revision-span:not(.revision-span-out) {
transition: 1s;
-webkit-transition: 1s;/*for chrome and safari*/
-moz-transition: 1s;/*for firefox*/
-ms-transition: 1s;/*for ie*/
-o-transition: 1s;/*for opera*/
transition: 1s;
}
.revision-span-out {
position:absolute;
opacity: 0;
}
Most of us know the simple opacity CSS rule, but recently I stumbled upon filter which can have opacity(amount) as it value - among other things. But what exactly is the difference between the two?
filter: opacity() is similar to the more established opacity property; the difference is that with filter: opacity(), some browsers provide
hardware acceleration for better performance. Negative values are not
allowed.
filter: opacity() applies transparency.
A value of 0% is completely transparent. A value of 100% leaves the
input unchanged. Values between 0% and 100% are linear multipliers on
the effect. This is equivalent to multiplying the input image samples
by amount. If the “amount” parameter is missing, a value of 100% is
used.
Source: https://css-tricks.com/almanac/properties/f/filter/
/*
* -----------
* filter: opacity([ <number> or <percentage> ])
* -----------
*/
.filter-opacity {
filter: opacity(0.3);
height: 5rem;
width: 5rem;
background-color: mediumvioletred;
}
/*
* -----------
* standard opacity
* -----------
*/
.just-opacity {
opacity: 0.3;
height: 5rem;
width: 5rem;
background-color: lawngreen;
}
<div class="filter-opacity">
filter-opacity
</div>
<div class="just-opacity">
just-opacity
</div>
I've found some difference between them both, especially in the Chrome browser.
If we set the CSS opacity property to an iframe tag, then we'll not be able to click any links inside this frame (I guess, it's a protection from clickjacking attack) while filter: opacity(0) allows us to click any links. I don't know, maybe it's an omission from Chrome developers' side.
filter in CSS had some different runs, namely for FireFox and MSIE.
In MSIE 5.5 on through 7, filter, also known as Alpha Filter, actually makes use of MSIE's DX Filter (no longer supported). However, in order to be more CSS2.1 compliant, in IE8 MS introduced -ms-filter to replace filter. The syntax is different in that the value of -ms-filter must be encased in quotes. Eventually, IE9 brought deprecation to this method and as of IE10, it is no longer used.
Another interesting note here, if you're wanting full compatibility for older IE, then you must make sure use of filter and -ms-filter must be very specific. For example, the following does not work in IE8 running IE7 compat mode:
element {
filter: alpha(opacity=50);
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
}
-ms-filter must come before filter in order to get more out of older IE compatibility.Like so:
element {
-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";
filter: alpha(opacity=50);
}
FireFox made use of filter as an experiment gone awry. I believe the original idea was to mock what IE was doing in using the Direct X engine. There was even a browser specific version, as there was for most browsers at one time. Eventually, HTML5/CSS3 announced use of the filter namespace and it now has a new purpose.
As of CSS3, filter now has a whole new meaning! Firefox docs stay open as if they plan to expand on this, though I've yet to see it (however they do crash JS if your CSS is not to its liking now!). Webkit (which will probably become standard in next update to CSS3) has started to implement filter to the point you can almost "photoshop" images for your site!
Since filter is changing so much, opacity would be the preferred method to use, however, as you can see, to be completely cross-browser compatible means being very thorough.
Browser specific alternates:
-webkit-filter: filter(value);
-moz-filter: filter(value);
-o-filter: filter(value);
-ms-filter: "progid:DXCLASS.Object.Attr(value)";
See Also:
What's compatible with opacity?
What's compatible with the newer filter?
keep in mind, not the same as Older IE's filter
What mind is behind this prioritize of CSS3 cross browser?
for example:
.box_scale {
-webkit-transform: scale(0.8); /* Chrome, Safari 3.1+ */
-moz-transform: scale(0.8); /* Firefox 3.5+ */
-ms-transform: scale(0.8); /* IE 9 */
-o-transform: scale(0.8); /* Opera 10.50-12.00 */
transform: scale(0.8); /* Firefox 16+, IE 10+, Opera 12.10+ */
}
first is -webkit-, second is -moz-, third is -ms- forth is -o- and at the end without any prefix. what is the point of this prioritize ? or this is not matter which one is first?
You can see an inverted staircase in the property names, starting with the longest (-webkit-) and ending with the shortest (-o-) and the unprefixed property, supported by indenting the declarations so that the colons and values line up.
Other than that there is no practical meaning to the order of prefixes — you can mix and match the order of your prefixes however you like, with one exception: the unprefixed property always comes last because it's the standardized version of the property, and you want browsers to choose to use that over their prefixed version to ensure you get the most standards-compliant behavior for that property.
The order is irrelevant as the selectors target specific browsers. Most people chose this method purely because it looks better than writing them without tabs.
Well as browsers ignore css codes they don't understand, so the order is not important. browser will use the one it understands and will ignore the others.
Is there a way to create a fade-in/fade-out effect on mouse over/out respectively that only uses CSS 3?
If there is, would you say that it is a good way to implement such an effect with CSS only or not?
To me, it seems like a presentation only issue so I'm not sure why JavaScript should be involved?
Are you looking for something like this: http://jsfiddle.net/hRuR9/2/ ?
It's pretty simple...
.box{
opacity: 0.0;
-webkit-transition: 0.5s all;
-moz-transition: 0.5s all;
}
.box:hover{
opacity: 1.0;
}
As for whether using it or not is a good idea, it depends on your target audience and which browsers you expect them to use or want to support. Recent versions of Safari, Chrome, and Firefox (and I believe Opera) support it. No idea about recent versions of IE, but you can pretty much forget about the older ones.