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像你這樣的人首先在那裏。這正是我需要的,謝謝。 –