如何在更少的时间内将属性名称作为参数传递给mixin [英] How to pass a property name as an argument to a mixin in less
本文介绍了如何在更少的时间内将属性名称作为参数传递给mixin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个函数/混合器,如果它已经很暗,则它的颜色会变深,但是当它很亮时,它的颜色会变浅(归一化/极端化?)
I want to make a function/mixin that will make a color darker if it is already dark but lighter when it is light (normalize/extremeize?)
是否可以通过传递属性名称(颜色,背景颜色,右边框颜色等)来做到这一点?
Is it possible to do this by passing a property name (color, background-color, border-right-color, etc)?
.normalize(@color, @amount, @prop: "color") when (lightness(@color) >= 50%)
{
@prop:lighten(@color, @amount);
}
.normalize(@color, @amount, @prop: "color") when (lightness(@color) < 50%)
{
@prop:darken(@color, @amount);
}
推荐答案
目前,这是less.js github上的功能请求.因此,请在less.js 1.4 ..中注意这一点,直到您可以像这样入侵它...
This is currently a feature request on less.js github. So look out for it in less.js 1.4.. until then you can hack it like so...
.mixin(@prop, @value) {
Ignore: ~"a;@{prop}:@{value}";
}
不太好,您会获得额外的财产,但这是目前的唯一方法.
Not very nice and you get an extra property but its the only way at the moment.
这篇关于如何在更少的时间内将属性名称作为参数传递给mixin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文