0

所以我试图让图像在“悬停”时旋转 360 次。但不幸的是它不是,我认为这可能是因为我使用了背景元素来显示图像,但我想不出如何以其他方式显示图像。
使用 bootstrap 3,不确定如何使用 glyphicons

<div class="services">
    <i class="icon-html5"></i>
    <h4 class="service-heading">HTML5</h4>
    <p>Developed with high level of coding and care to provide everyone with a HTML5 compliant markup.</p>
</div>
.services{
    background-color:#F5F5F5;
    border-radius: 5px 5px 5px 5px;
    cursor: pointer;
    margin:60px 0;
    padding:14px;
    position: relative;
}
.services i{
    border:10px solid #FFFFFF;
    border-radius: 50% 50% 50% 50%;
    color:#F4F4F4;
    font-size: 18px;
    height:100%;
    left:50%;
    line-height: 100%;
    margin: -60px 0 0 -60px !important;
    padding:0 !important;
    position: absolute;
    top:0px;
    transition: all 0.3s ease-in-out 0s;
    width:140px;
    background-color:#F47E7E;
}
.services:hover > i{
    animation: 1.5s linear 0s normal none infinite spinAround;
    border: 10px solid #FFFFFF;
}
.icon-html5{
    background-image: url('../img/html5.png');
    background-repeat: no-repeat;
    animation: 1.5s linear 0s normal none infinite spinAround;
    border: 10px solid #FFFFFF;
    background-position:center;
}

JS 小提琴 - http://jsfiddle.net/MJXrM/1/

谢谢!

4

3 回答 3

1

你在你的CSS中缺少这样的东西:

@-moz-keyframes spinAround { 
    from {-moz-transform: rotate(00deg); } 
    to {-moz-transform: rotate(360deg);}
}

@-webkit-keyframes spinAround {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}

@keyframes spinAround {
    from {transform:rotate(0deg);}
    to {transform:rotate(360deg);}
}

见小提琴:http: //jsfiddle.net/MJXrM/3/

我也改变了这个:

.services:hover > i

进入这个:

.services > i:hover
于 2013-08-09T18:06:56.130 回答
1

如果您使用较少的引导程序,您可以这样做:

.services > i:hover {
    .icon-spin;
}
于 2013-09-05T10:55:01.300 回答
-1

您是否考虑使用精灵表动画来实现您的无限旋转?如果你有一个动画文件,你可以用下面的代码来实现。这种方式更兼容旧浏览器和现代浏览器。

<div class="spinner-bg">
    <div id="spinner">
    </div>
</div>

.spinner-bg
{
    width: 44px;
    height: 41px;
    background:#000000;
}

#spinner
{
    width: 44px;
    height: 41px;
    background:url(./preloadericon.png) no-repeat;
}

<script>
var currentbgx = 0;
var circle = document.getElementById("spinner");
var circleTimer = setInterval(playAnimation, 100);

function playAnimation() {
    if (circle != null) {
        circle.style.backgroundPosition = currentbgx + "px 0";
    }

    currentbgx -= 44; //one frame width, there are 5 frame
    //start from 0, end at 176, it depends on the png frame length
    if (currentbgx < -176) {
        currentbgx = 0;
    }
}
</script>

您还可以在此处找到更多 HTML 动画实现:

加载 AJAX 微调器动画

在 HTML5 游戏中创建 CSS 动画

于 2014-02-13T01:32:53.200 回答