单击时旋转字体真棒图标 [英] Rotate Font Awesome Icon On Click

查看:82
本文介绍了单击时旋转字体真棒图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Font Awesome V形旋转180º点击。

I'm trying to make a Font Awesome chevron rotate 180º on click.

这是 JSFiddle ,到目前为止我已经尝试过了。我还希望它围绕中心旋转,所以我使用了其他线程

Here's the fiddle of JSFiddle that has what I've tried so far. I also wanted it to spin around the center so I used this other thread.

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过渡会更容易:

I believe it would be easier to do this with CSS transitions:

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"); 
});

演示小提琴

Demo fiddle

这篇关于单击时旋转字体真棒图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆