CSS3のアイコンの色をjQueryでマウスの上に変更します
-
26-12-2019 - |
質問
私はCSSで作成されたCSS3アイコンを持っています。 > http://jsfiddle.net/5c9gn/
js:
$('.ok').mouseenter(function(){
$(this).parent().find('.ok:after, .ok:before').css('background','#ccc');
$(this).css('background','#33CC33');
});
$('.ok').mouseleave(function(){
$(this).parent().find('.ok:after, .ok:before').css('background','#ccc');
$(this).css('background','#ccc');
});
.
CSS:
.ok{height:40px; width:40px; display:block; position:relative; margin-left: auto; margin-right: auto;}
.ok:after, .ok:before{content:''; height:32px; width:10px; display:block; background: #ccc; position:absolute; top:6px; left:18px; transform:rotate(45deg);-webkit-transform:rotate(45deg);-moz-transform:rotate(45deg);-o-transform:rotate(45deg);-ms-transform:rotate(45deg);}
.ok:before{height:16px; transform:rotate(-45deg);-webkit-transform:rotate(-45deg);-moz-transform:rotate(-45deg);-o-transform:rotate(-45deg);-ms-transform:rotate(-45deg); top:18px; left:6px;}
.
アイコンの色を変更しようとしている間は少し問題があります。アイコンではなく背景色を常に変更します。 誰かが私を助けてくれることができますか? ありがとう
解決
他のヒント
このCSSを追加する
.ok.mouseover:after, .ok.mouseover:before{
background: #33CC33;
}
.
とこのJSコードをこの
に更新します。$('.ok').mouseenter(function(){
$(this).addClass('mouseover');
});
$('.ok').mouseleave(function(){
$(this).removeClass('mouseover');
});
. 所属していません StackOverflow