简体   繁体   English

较少的CSS mixin参数

[英]Less CSS mixin arguments

I have this Less mixin - 我有这个Less mixin -

.css3-transitions(@property: color, @duration: 0.3s, @transition: ease-in) {
  -webkit-transition:@property @duration @transition;
      -moz-transition:@property @duration @transition;
           transition:@property @duration @transition;
}    

and I was to use in on a class but exclude the easing and apply it to opacity so I do this.. 而我是在一个类中使用但排除缓动并将其应用于不透明度所以我这样做..

.myClass{
 .css3-transition(opacity);
} 

but the easing in inserted as well. 但插入的缓和也是如此。 eg the CSS outcome is this... 例如,CSS的结果是......

 -webkit-transition: opacity 0.3s ease-in;
  -moz-transition: opacity 0.3s ease-in;
  transition: opacity 0.3s ease-in;

How would I exclude the easing? 我如何排除宽松政策?

Assuming your mixin code stays the same, you can specifically set values in LESS at the time of the call like this (here I pass "nothing" to the @transition by giving it an escaped empty string ~'' ): 假设你的mixin代码保持不变,你可以在调用时特别设置LESS中的值(这里我通过给它一个转义的空字符串~''将“传递给没有”给@transition ):

.myClass{
 .css3-transitions(opacity, @transition: ~'');
}

Note how I do not need to worry about it being the third parameter because I am explicitly telling it the parameter I am setting, so I do not need to pass a duration as it will stay the default. 注意我不需要担心它是第三个参数,因为我明确地告诉它我正在设置的参数,所以我不需要传递一个持续时间,因为它将保持默认值。

The 'ease-in' easing is included by default. 默认情况下包含“缓入”缓动。 If you leave it out, the mix-in will assume you want the default easing, which is 'ease-in', as defined in the mix-in. 如果你把它放在外面,混合将假定你想要默认的缓和,这是'轻松',如混合中所定义的。 You'll have to specify a different easing if that's what you need, or modify the mix-in code. 如果这是你需要的,你必须指定一个不同的缓动,或修改混合代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM