LESS transition mixin with prefixes - less

I was wondering if it's possible to create a LESS mixin that I could use like this:
.transform(transition, .5s, ease-out);
and has this CSS as output:
-webkit-transition: -webkit-transform .5s ease-out;
-moz-transition: -moz-transform .5s ease-out;
transition: transform .5s ease-out;
but I would also be able to use the same mixin for other properties (i.e. .transition(opacity, .5s) should output to -webkit-transition:opacity .5s; -moz-transition:opacity .5s; transition:opacity .5s;
Thanks!
Leon

Since Less version 2 you can use the autoprefix postprocessor plugin and the consensus is that you should use it for best practice.
The Less autoprefix plugin can be found at: https://github.com/less/less-plugin-autoprefix.
After installing the you can run:
echo "selector {transition: transform .5s ease-out;}" | lessc - --autoprefix="last 20 versions"
The preceding command outputs:
selector {
-webkit-transition: -webkit-transform 0.5s ease-out;
-moz-transition: -moz-transform 0.5s ease-out;
-o-transition: -o-transform 0.5s ease-out;
transition: transform 0.5s ease-out;
}
You should consider Graceful degredation and run the autoprefix plugin without any browser argument. (lessc --autoprefix). Then your output will look like that shown below:
selector {
-webkit-transition: -webkit-transform 0.5s ease-out;
transition: transform 0.5s ease-out;
}
Notice that you can not use the auto prefix plugin when using less.js to compile your Less code in the browser. For client side compiling you can use the -prefix-free library.

Related

Ionic 4 --background transition

how to make transition of background-color of ion-toolbar?
The problem is, in Ionic 4 the background-color is set by --background.
This is my NOT working .scss code:
ion-toolbar.transparent{
--background: red;
transition: 1000ms linear;
}
ion-toolbar.transparent:hover{
--background: green;
}
Please check the below codes, remove the transparent class name from the ion-toolbar, also don't use color attribute in ion-toolbar
<ion-toolbar>
<ion-title>
Ionic Title
</ion-title>
</ion-toolbar>
For style
ion-toolbar{
--background: red;
transition: 1000ms linear;
}
ion-toolbar:hover{
--background: green;
}

Vue transition - transform translate not working

So I have the following code:
HTML:
<transition name="slide-left-centered">
<div v-if="test" style="position: fixed; transform: translate(0, 100%)">
test code
</div>
</transition>
CSS:
.slide-left-centered-enter,
.slide-left-centered-leave-to {
transform: translateX(-100%);
opacity: 0;
}
.slide-left-centered-enter-active {
transition: all .3s ease;
}
.slide-left-centered-leave-active {
transition: all .5s ease;
}
If I were to toggle it on and off, it only fades with the opacity but does not move. This works once I remove transform from the HTML.
https://codesandbox.io/s/92mv6ov6xy
I have figured out the problem
This won't work as inline styling takes precedent.
In my real problem, it is using a class which is a child of another class. The reason why it didn't work was because of specificity. I have added !important to the transition class and now it works e.g.
transform: translateX(-100%) !important;

I want to fade the whole background on focus

I want to fade the whole background on focus the search field. I need only css, If there is a way please let me know I am stuck here for 2 days.
There are so many ways this can be done:
1) Use jQuery to add this class when the search field has focus:
.fader {
opacity: .5;
-webkit-transition: opacity .25s ease-in-out;
-moz-transition: opacity .25s ease-in-out;
transition: opacity .25s ease-in-out;
}
2) Use jQuery to apply this method when the search field has focus:
$("body").fadeOut(2500); // the higher the number the longer it takes to fade
Note for IE 8 compatibility: Use opacity: 0.5; filter: alpha(opacity=50);

Border radius cutting/image overlapping in Safari

I have looked through a few other questions and answers but still can't get this working in Safari (v 5.1.7).
Here is my code - jsfiddle
.services {
width: 218px;
float: left;
margin-right: 29px;
}
.services img {
border: solid 8px #ccc;
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
border-radius: 50%;
}
.services a img:hover {
border: solid 8px #333;
-o-transition: all 1s ease 0s;
-ms-transition: all 1s ease 0s;
-moz-transition: all 1s ease 0s;
-webkit-transition: all 1s ease 0s;
transition: all 1s ease 0s;
}
The image is square 218px x 218px, so I'm guessin that has something to do with it, but I wanted it like that so it would look decent enough in older browsers that don't support border radius.
It's probably something simple, but I'm still stuck on this.
Thanks.
Al.
Answer from Sitepoint:
Hm, tricky. It works if you put the border on the instead:
Code:
.services {
width: 218px;
float: left;
margin-right: 29px;
}
.services img {
vertical-align: top;
}
.services img, .services a {
border-radius: 50%;
}
.services a {
border: 8px solid #ccc;
display: inline-block;
}
.services a:hover {
border: 8px solid #333;
-o-transition: all 1s ease 0s;
-ms-transition: all 1s ease 0s;
-moz-transition: all 1s ease 0s;
-webkit-transition: all 1s ease 0s;
transition: all 1s ease 0s;
}
You can just use border-radius now, without the vendor prefixes, as all browsers that are going to support it now.

Multiple properties are getting treated as separate arguments in mixins

I'm trying to write a mixin, but I can't seem to get the arguments working the way I want: multiple properties are getting treated each as a separate argument.
Current Code
.transition(#property: all, #time: 1s, #timing: ease-in-out) {
-moz-transition: #property #time #timing;
-webkit-transition: #property #time #timing;
-o-transition: #property #time #timing;
transition: #property #time #timing;
}
a {
.transition(color, opacity, .5s);
}
Desired Output
a {
-moz-transition: color, opacity .5s ease-in-out;
-webkit-transition: color, opacity .5s ease-in-out;
-o-transition: color, opacity .5s ease-in-out;
transition: color, opacity .5s ease-in-out;
}
Actual Output
a {
-moz-transition: color opacity .5s;
-webkit-transition: color opacity .5s;
-o-transition: color opacity .5s;
transition: color opacity .5s;
}
Any ideas?
I'd suggest using LESS's escape function, i.e.:
a:link, a:visited {
color: green;
opacity: .5;
font-size: 1em;
}
a:hover {
color: red;
opacity: 1;
font-size: 2em;
.transition(e("font-size, color"));
}
And though it seems that LESS accepts that, it will only animate the last property in the comma-separated string you send through. A pity.
Using the solution found here works with one AND multiple arguments:
.transition (#value1,#value2:X,...)
{
#value: ~`"#{arguments}".replace(/[\[\]]|\,\sX/g, '')`;
-webkit-transition: #value;
-moz-transition: #value;
-ms-transition: #value;
-o-transition: #value;
transition: #value;
}
Using it this way:
.transition(color, opacity .5s ease-in-out);
yields:
-webkit-transition: color, opacity .5s ease-in-out;
-moz-transition: color, opacity .5s ease-in-out;
-ms-transition: color, opacity .5s ease-in-out;
-o-transition: color, opacity .5s ease-in-outt;
transition: color, opacity .5s ease-in-out;
If you want to pass a comma-separated list as an argument to mixin, you can simply use a semicolon to separate arguments.
Code below works as desired with the mixin you defined:
a {
.transition(color, opacity; .5s);
}
Less mixins have the ability to use semicolon-separated arguments (as well as comma-separated). They recommend you always use semicolons.
If a semicolon is present in a list of arguments when the mixin is called, everything between semicolons will be considered as arguments, even if those things have commas in them. This allows you to pass a comma-separated list as ONE argument. If a semicolon is NOT present, it will treat commas as argument separators.
.transition(#property: all; #time: 1s; #timing: ease-in-out) { // NOTE THE SEMICOLONS
transition: #property #time #timing;
}
a {
.transition(color,opacity; .5s); // SEMICOLON AFTER 'opacity'
}
b {
.transition(color,opacity, .5s); // COMMA INSTEAD
}
output:
a {
transition: color,opacity .5s ease-in-out;
}
b {
transition: color opacity .5s; // invalid syntax
}
Note that the syntax of the shorthand transition property must be a comma-separated list of single transitions. So b has an invalid value, and a has two transitions, in which the unspecified values default to their initial value:
color 0s ease 0s
opacity .5s ease-in-out 0s
This is likely not what you intended. (It looks like you wanted color .5s ease-in-out 0s and opacity .5s ease-in-out 0s.)
Now you might be wondering, "how do I pass a comma-separated list as a single argument, when there are no other arguments?" Simply append a dummy semicolon at the end of the list.
.transition(#property: all; #time: 1s; #timing: ease-in-out) {
transition: #property #time #timing;
}
b {
.transition(color,opacity;); // DUMMY SEMICOLON AFTER ARGUMENT
}
i {
.transition(color,opacity); // MISSING SEMICOLON
}
output:
b {
transition: color,opacity 1s ease-in-out; // 'color,opacity' is the first argument
}
i {
transition: color opacity ease-in-out; // 'color' is 1st arg, 'opacity' is 2nd arg
}
Again, syntax for i is invalid, and b has two transitions:
color 0s ease 0s
opacity 1s ease-in-out 0s