LESS transition mixin with prefixes

岁酱吖の 提交于 2019-11-26 23:40:42

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/27620308/less-transition-mixin-with-prefixes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!