Multiple transitions for Twitter bootstrap .transition? - css

I am wanting to animate two properties in Bootstrap v2.1.0,
The opacity and the margin.
I have tried:
.transition(opacity 0.5s, margin 0.25s);: No output
.transition('opacity 0.5s, margin 0.25s');: Invalid CSS output
.transition(opacity 0.5s); .transition(margin 0.25s);: Margin overrides opacity.
Note that I am using lessphp so solutions that use the JavaScript regex will not work.
I know I could copy the mixin and modify it to accept two parameters as well, but that just seems hacky, surely there is a better way?

Two Options (Depending on version of LESS)
LESS (1.3.3+)
The less2css.org shows this works with LESS 1.3.2 on experimentation, but the issue documentation seems to indicate this is a 1.4 release addition.
Whenever it became effective, at some point, the semicolon was introduced as a possible variable separator in parametric mixins while still allowing commas. The presence of a ; causes commas to be viewed not as separating variables, but rather as part of the value of the variable itself (a comma separated list). This then allows (to quote the site) us to use a "dummy semicolon to create mixin call with one argument containing comma separated css list."
Therefore the following works to produce the same output as above without the escaped string (NOTE the "dummy" semicolon put at the end of the variable entry, right before the closing parenthesis of the parametric mixin call):
.transition(opacity 0.5s, margin 0.25s;);
|
semicolon here
LESS (pre 1.3.3, but also works in later versions)
Do a string interpolation (~) for the passed in variables:
.transition(~"opacity 0.5s, margin 0.25s");
Both solutions output:
-webkit-transition: opacity 0.5s, margin 0.25s;
-moz-transition: opacity 0.5s, margin 0.25s;
-o-transition: opacity 0.5s, margin 0.25s;
transition: opacity 0.5s, margin 0.25s;

Related

Transition-delay in transition shorthand?

In CSS transition shorthand is essential transition-delay? I would like to know if is possible to use shorthand without transition-delay...
Because i have a module on my website that minimize ces and i read that minification delete units to transition delay, and if is without unit transition doesn't work with firefox (for me also with chrome).. So:
So can i write in this way:
transition: font-size 2s ease-out; //without 0s of transition delay
Is possible ???
Thanks a lot and sorry for my english :)

How to handle CSS animations efficiently

IMHO there are 3 possible ways to declare an animation for certain HTML elements on the page:
* { transition: all .3s ease; } - Regarding lines of code, file size, and ease of use, I find this the most suiting solution to handle CSS animations on a page. But I do know using the asterisk selector has quite a heavy impact on performance, so this option doesn't seem like the most efficient one. Also, this sometimes causes for unwanted animations on objects where it's not needed.
.animated { transition: all .3 ease; } - Again regarding lines of code, file size and ease of use (in CSS), this looks like the optimal solution. We create a class specifically for animations, and just add this class to all elements we need an animation on. Variations can be made (adjusting the speed etc.) with other classes. But, this does require that every single HTML element you would like to animate should get this class, which means that when for some reason the classname changes one day, all these references should be updated.
.class1, .class2, .class3, ... { transition: all .3s ease; } - Another solution to this problem could be to have one giant selector for every HTML element in need of animation. This could be causing a giant CSS selector, which is not very file size friendly, nor very readable IMO. But, it does have some advantages too - there's only one place to be updated whenever an element needs animation.
So my question is:
What is the most efficient way to handle CSS animations on a HTML page?

Browser-specific prefixes with a CSS transition on transform

According to caniuse.com, for those browsers that support both CSS transition and CSS transform, combinatorically there are at least three different types:
Those that require the -webkit- prefix on both transition and transform (e.g. Safari 6, Android browser < 4.4).
Those that only require the -webkit- prefix on transform (e.g. Chrome 3x).
Those that require prefixes on neither (e.g. FF and IE10/11).
How can I safely write my transition styles so that they are parsed correctly in each type? I see two options:
-webkit-transition: -webkit-transform 300ms;
transition: -webkit-transform 300ms, transform 300ms;
or
-webkit-transition: -webkit-transform 300ms;
transition: -webkit-transform 300ms;
transition: transform 300ms;
Now because of type 2 and type 3 browsers I need to have a prefix-less transition for both -webkit-transform and transform. The problem with the first option is I worry that type 2 and type 3 browsers will not be able to parse the second line, since they will always contain an unrecognized property. The question is, how do browsers handle invalid properties inside a transition--ignore the entire transition style or just skip the invalid property?
I thought this may be mitigated by separating it into two properties so that if one is not parseable it will just be ignored. Apart from this second option being a bit verbose, I still wonder if, in the case of type 2 browsers, the third transition will be unparseable and "reset" the transition back to null.
Any ideas how these perform, generally? Also, which of these are future-compliant for when Chrome et al. switch from -webkit-transform to the prefix-less transform?
UPDATE NOTICE Unfortunately it turns out Safari at the time of this post does not follow the standard outlined in the W3 Specification below, and including both a webkit prefixed property and a prefix-less property after transition will cause it to break and not be animated at all. I am still exploring this issue for a good general solution but it looks like until Safari fixes this, there may not be one that works everywhere, and for all future properties, without adjusting your CSS rules per browser dynamically with JavaScript.
If you add an unrecognized or invalid property to a list of transition properties, the valid properties in the list will still be added (except on Safari, see notice above).
According to section 2.1 of the w3 Specification for CSS Transitions:
If one of the identifiers listed is not a recognized property name or is not an animatable property, the implementation must still start transitions on the animatable properties in the list using the duration, delay, and timing function at their respective indices in the lists for ‘transition-duration’, ‘transition-delay’, and ‘transition-timing-function’.
W3 Specification for CSS Transitions
If you take the following style, the width property will still be animated despite being preceded by an invalid and unrecognized property.
transition: unrecognizedProperty 2s, width 2s;
If you follow a transition rule with another transition rule (with the same prefixing or lack thereof), the first rule will be overwritten and no longer applied even if the second rule only has invalid properties listed on the right hand side.
If you try the following style the width will not be animated because the first rule will be overwritten by the second rule, which effectively does nothing since "unrecognizedProperty" is not recognized.
transition: width 2s;
transition: unrecognizedProperty 2s;
Based on this I believe your first approach is correct.
-webkit-transition: -webkit-transform 300ms;
transition: -webkit-transform 300ms, transform 300ms;
The first rule will only be applied if -webkit-transition is recognized, in which case since transform came out after transition it will definitely have to be prefixed and we can omit the unprefixed transform property (although I don't think it would hurt to leave it). The second rule will only be applied if unprefixed transition is recognized, in which case whichever of the right-hand side properties that are recognized by the browser will be applied, even if other properties in the list are not recognized.
Your second approach is flawed since the second rule will always be overwritten by the third rule regardless of if any properties on the right hand side are or are not recognized.
I believe the complete list of browser prefixed properties to guarantee that you apply transition of 2s to transform on all browsers that are capable is the following, but please read the rational below because it only happens to be this neat for this property pair by chance:
-webkit-transition: -webkit-transform 2s;
-moz-transition: -moz-transform 2s;
-o-transition: -o-transform 2s;
transition: transform 2s;
Note there is no such thing as -ms-transition, but there is a -ms-transform. That being said transition was not added to IE until 10 where -ms-transform was also outdated by unprefixed transform. Hence for IE the only rule we need is "transition: transform".
I will additionally note that any time we have a browser prefix for transition (< Chrome 26, < Firefox 16, < Safari 6.1, < Opera 12.1), then transform was definitely still prefixed as well (< Chrome 36, < Firefox 16, all Safari, < Opera 23), meaning we can leave off the unprefixed version of transform following a prefixed rule.
Since Firefox released unprefixed transition at the same time as their unprefixed transform, we do not need the prefixed "-moz-transform" on the right-hand side of the unprefixed "transition".
Opera at some point used -webkit- prefix for transform in addition to -o-, however they started using -webkit-transform in version 15, after starting to use prefixless transition in version 12.1, so we do not need to include the -webkit-transform after -o-transition. Also since Opera only used prefixless or -webkit-transform after version 12.1, we do not need to include -o-transform after the prefixless transition.
In this case we do not have to include -webkit-transform to the right of prefix-less transition because browsers that only recognize -webkit-tranform will fall back to -webkit-transition and still apply this property.
If you don't mind the length of your CSS though, the following should be a safe generalized solution for ensuring proper browser prefixing of transition and a prefixed right hand property. UPDATE NOTICE As it turns out this approach may not be safe on Safari since they do not follow the W3 standard on ignoring unrecognized properties to the right of transition if there is one that is prefixed and one that is not.
-webkit-transition: -webkit-property,
property;
-moz-transition: -moz-property,
property;
-ms-transition: -ms-property,
property;
-o-transition: -o-property,
-webkit-property,
property;
transition: -webkit-property,
-moz-property,
-ms-property,
-o-property,
property;
I believe the transition prefix that is unrecognized is simply skipped until a recognized one is found.
I am currently using this for a site and it works for us.
CSS
.viewElement{
-webkit-transform: translatex(0) translatey(500px);
-moz-transform: translatex(0) translatey(500px);
-o-transform: translatex(0) translatey(500px);
-ms-transform: translatex(0) translatey(500px);
transform: translatex(0) translatey(500px);
-ms-filter: "progid: DXImageTransform.Microsoft.Alpha(Opacity=0)";
filter: alpha(opacity=0);
opacity: 0.0;
-webkit-transition: all .8s ease-out;
-moz-transition: all .8s ease-out;
-o-transition: all .8s ease-out;
-ms-transition: all .8s ease-out;
transition: all .8s ease-out;
}

How does Impress.js's CSS work?

I was reading about Impress.js and I have some questions about the code below (Part of the Inpress's demo).
.impress-enabled .step {
margin: 0;
opacity: 0.3;
-webkit-transition: opacity 1s;
-moz-transition: opacity 1s;
-ms-transition: opacity 1s;
-o-transition: opacity 1s;
transition: opacity 1s;
}
.impress-enabled .step.active { opacity: 1 }
My questions:
What is .impress-enabled class here for?
So class .active is applied on the step currently displayed? And thus, its opacity changes to 1 when its displayed and back to .3 when its next one is displayed; as described in .impress-enabled .step above it, right?
Thanks for help
if javascript is deactivated by the visitors browser, he won't get a .impress-enabled class at all, because it is added via javascript. that's how they could separate a javascript and a non-javascript version (simply deactivate javascript for a moment and visit an example page of impress.js again). So if you have js activated, the class "bored" gets removed and a class called "impress-on-bored" and "impress-enabled" gets activated.
Yes. You're right.
impress-on-ID can be used to add slide specific js or css code when it becomes active. For example, if your slides are small and multiple slides are contained in the browser window, we can initially hide all the slides other than first slide.
Once specific slide becomes active, it will get impress-on-ID class. We can use this class to make the step visible.
If you want to know more, read my book on Building Impressive Presentations with impress.js

Targeting a specific CSS transform with transition

Is there a way to target a specific CSS Transform property (such as Rotate(), Scale(), TranslateX()) with the Transition property? Something along the lines of:
transition: 200ms transform-Rotate, 500ms transform-TranslateX;
No. The CSS transition spec states that only single CSS properties can be used in the transition-property field. transform is a CSS property. Rotate(), Scale(), etc, are transform functions, not CSS properties.

Resources