$(document).ready(function() {
$('.button').hover(function() {
$(this).toggleClass('button-hover',200);
},function() {
$(this).toggleClass('button-hover',200);
});
});
$(document).ready(function() {
$('.button-rounded').hover(function() {
$(this).toggleClass('button-rounded-hover',200);
},function() {
$(this).toggleClass('button-rounded-hover',200);
});
});
<div class="button">Add class `button-hover` to this `div` on mouse over.</div>
<div class="button button-rounded">Add class `button-hover` and
class `button-rounded-hover` to this `div` on mouse over.</div>
2番目divのアニメーション全体を実行するには、400ミリ秒かかります。トグルの場合は200ミリ秒button-hover、次にトグルの場合はさらに200ミリ秒かかりbutton-rounded-hoverます。これらのトグルを同時に実行するにはどうすればよいですか?
ノート:
- 私はOOCSSを使用しているので、
button-roundedextendsbutton、button-rounded-hoverextendsbutton-hover。button-rounded-hoverあまり正確に定義したくないbutton-hoverのは、DRY(Do n't Repeat Yourself)ではないため、2番目のクラスで2つのクラスと2つのホバー呼び出しを使用している理由ですdiv。 - 両方のアクションに200ミリ秒かかる必要があります。どちらも0(瞬時)にしたくありません。