1
我有以下更少的代码:反向悬停国少
.favourite-action-link {
&:after {
color:@grey;
content: '\e836';
}
&.is-favourite:after {
color:@red;
content: '\e811';
}
&:hover {
&:after {
color:@red;
content: '\e811';
}
&.is-favourite:after {
color:@grey;
content: '\e836';
}
}
}
的基本目标是,有一个正常的状态和悬停状态,当另一个阶级存在被逆转。我会重复这个做其他的动作(例如.share-action-link
,.review-action-link
等),这看起来很乱。有没有办法创建一个mixin,以便我可以这样提供:
.favourite-action-link {
&:after {
color:@grey;
content: '\e836';
&:hover {
color:@red;
content: '\e811';
}
.reverseOnClass(is-favourite);
}
}
或者类似的东西?我能想到的,到目前为止的唯一方法是做:
.favourite-action-link {
&:after {
color:@grey;
content: '\e836';
}
&.active:after {
color:@red;
content: '\e811';
}
}
,然后使用jQuery,而不是做悬停 - 上(isHovering XOR hasClass(is-favourite))
切换.active
- 但转弯少进LESS + jQuery是固定的相反混乱/可维护性问题。
我没有被绑定到一个mixin的任何特定原因 - 我不相信我只看了它,只要我做了,没有简化sele像你这样的人首先在那里。这正是我需要的,谢谢。 –