2

我是新手。为什么这段代码不起作用?我想让小鸟飞起来。

我的html:

<img src="http://dl.dropboxusercontent.com/u/105046436/tw.png" />
<br>
<div class="twitter-bird"></div>

我的 CSS:

.twitter-bird {
    background-image: url(http://dl.dropboxusercontent.com/u/105046436/tw.png);
    display: inline-block;
    height: 38px;
    width: 37.5px;
}

.twitter-bird:hover {
    animation: fly 0.2s steps(3) 0 infinite;
}

@keyframes fly {
    from { background-position: 0 0; }
    to { background-position: -112.5px 0; }
}

JSFiddle:http: //jsfiddle.net/6qHMG/

我想要的是:

我想更改图像的背景位置。

怎么了:

悬停时图像位置不会改变。

编辑:我认为背景图像位置没有正确改变。背景位置似乎没有改变。我该如何background-position:入驻@keyframes fly

4

1 回答 1

8

这里是:

你必须添加供应商前缀

.twitter-bird {
    height: 38px;
    width: 37.5px;
    background-image: url("http://dl.dropboxusercontent.com/u/105046436/tw.png");
}

.twitter-bird:hover { 
    -webkit-animation: fly .4s steps(3) infinite;
       -moz-animation: fly .4s steps(3) infinite;
        -ms-animation: fly .4s steps(3) infinite;
         -o-animation: fly .4s steps(3) infinite;
            animation: fly .4s steps(3) infinite;
}

@-webkit-keyframes fly {
   from { background-position:    0px; }
     to { background-position: -112.5px; }
}

@-moz-keyframes fly {
   from { background-position:    0px; }
     to { background-position: -112.5px; }
}

@-ms-keyframes fly {
   from { background-position:    0px; }
     to { background-position: -112.5px; }
}

@-o-keyframes fly {
   from { background-position:    0px; }
     to { background-position: -112.5px; }
}

@keyframes fly {
   from { background-position:    0px; }
     to { background-position: -112.5px; }
}

小提琴:http: //jsfiddle.net/6qHMG/4/

于 2013-06-14T12:34:40.023 回答