簡體   English   中英

單擊時旋轉字體真棒圖標

[英]Rotate Font Awesome Icon On Click

我正試圖讓Font Awesome V形旋轉180º點擊。

這是JSFiddle的小提琴,它具有我迄今為止所嘗試過的功能。 我也希望它圍繞中心旋轉,所以我使用了另一個線程

HTML

<div class="fa fa-chevron-up"><a href="#">^</a></div>

CSS

.rotate {
-webkit-animation: spin1 2s  linear;
-moz-animation: spin1 2s  linear;
-o-animation: spin1 2s  linear;
-ms-animation: spin1 2s  linear;
animation: spin1 2s  linear;

-webkit-transform-origin: 50% 50%;
-moz-transform-origin: 50% 50%;
-o-transform-origin: 50% 50%;
transform-origin: 50% 50%;
width: 256px;
height: 256px;
}

@-webkit-keyframes spin1 {
0% { -webkit-transform: rotate(0deg);}
100% { -webkit-transform: rotate(180deg);}
}
@-moz-keyframes spin1 {
0% { -moz-transform: rotate(0deg); }
100% { -moz-transform: rotate(180deg);}
}
@-o-keyframes spin1 {
0% { -o-transform: rotate(0deg);}
100% { -o-transform: rotate(180deg);}
}
@-ms-keyframes spin1 {
0% { -ms-transform: rotate(0deg);}
100% { -ms-transform: rotate(180deg);}
}
@-keyframes spin1 {
0% { transform: rotate(0deg); }
100% { transform: rotate(180deg);}
} 

JS

$(".fa-chevron-up").click(function(){
 $(this).toggleClass("rotate")  ; 
})

我相信使用CSS轉換更容易做到這一點:

CSS

.rotate{
    -moz-transition: all 2s linear;
    -webkit-transition: all 2s linear;
    transition: all 2s linear;
}

.rotate.down{
    -ms-transform: rotate(180deg);
    -moz-transform: rotate(180deg);
    -webkit-transform: rotate(180deg);
    transform: rotate(180deg);
}

jQuery的

$(".rotate").click(function(){
    $(this).toggleClass("down"); 
});

演示小提琴

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM