这是我的div。
#div1{
position: absolute;
top: 50%;
left: 50%;
margin-left:-100px;
margin-top: 420px;
width: 158px;
height: 158px;
background-image:url(images/background.png);
}
我需要360度的鼠标经过事件的背景图像旋转动画。有人能帮我吗?谢谢。
发布于 2012-09-20 05:36:35
以下是您的请求:
<div id="div1">rterterrt
teteterrtetre<div id="div2">
</div></div>
。
#div1{
position: absolute;
top: 50%;
left: 50%;
margin-left:-100px;
/*margin-top: 420px;*/
width: 158px;
height: 158px;
}
#div2{
/*margin-top: 420px;*/
width: 158px;
height: 158px;
background-image:url(http://www.commentsyard.com/cy/01/6474/Mixed%20Flowers%20and%20a%20Bear.jpg);
}
#div2:hover {
-webkit-animation-name: rotate;
-webkit-animation-duration: 2s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-timing-function: linear;
-moz-animation-name: rotate;
-moz-animation-duration: 2s;
-moz-animation-iteration-count: infinite;
-moz-animation-timing-function: linear;
}
@-webkit-keyframes rotate {
from {-webkit-transform: rotate(0deg);}
to {-webkit-transform: rotate(360deg);}
}
发布于 2012-09-20 05:50:47
不能通过CSS (级别2,3)的方式旋转背景图像。因此,您唯一的选择是对该图像使用单独的元素,并将该元素作为一个整体进行旋转/动画。
但您将能够在CSS level 4中做到这一点。
发布于 2014-09-11 03:28:26
您可以使用伪元素来实现这一点
#div1{
position: absolute;
top: 50%;
left: 50%;
margin-left:-100px;
margin-top: 420px;
}
#div:before {
content: "";
position: absolute;
width: 158px;
height: 158px;
background-image:url(images/background.png);
transition: all 1s linear;
}
#div:hover:before {
transform:rotate(360deg);
}
https://stackoverflow.com/questions/12506305
复制相似问题