我想做一个CSS3变换:rotate(360deg);在过渡1s; 在背景图像而不是单独的图像(元素).. 这可能吗?我已经搜索了谷歌,但没有成功! 我想要实现的是:
#footerLogo {
background: url('ster.png'),
-moz-transition: -moz-transform 1s,
transition: transform 1s,
-o-transition: -o-transform 1s,
-webkit-transition: -webkit-transform 1s;
background-position: #outlinedtotheleft;
}
#footerLogo:hover {
background: transform: rotate(360deg);
-o-transform: rotate(360deg);
-moz-transform: rotate(360deg);
-webkit-transform: rotate(360deg);
}
我希望这是可能的!我知道JS(jQuery)很容易用:
$('#something').hover(function(){morecodehere});
...但我想知道是否可以只用CSS(3)
HTML:
<div id="footerLogo">
<img src="carenza.png"/>
</div>
答案 0 :(得分:9)
当然可以,尝试这样的事情:
<强> HTML 强>
<div id="planet">
</div>
<强> CSS 强>
#planet {
width:200px;
height:200px;
background: transparent url(http://cdn3.iconfinder.com/data/icons/nx11/Internet%20-%20Real.png) no-repeat center center;
}
#planet {
-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);}
}
@-moz-keyframes rotate {
from {-moz-transform:rotate(0deg);}
to { -moz-transform:rotate(360deg);}
}
答案 1 :(得分:5)
我认为您不能将变换应用于背景图像本身(与div分开)。但是,您可以旋转整个div,包括使用过渡来为其设置动画(here's a working example。)< / p>
如果您能描述想要达到的确切效果,这可能会有所帮助吗?
代码:
#footerlogo {
width: 200px;
height: 200px;
background-image: url(http://lorempixum.com/200/200);
-webkit-transition: -webkit-transform 1s;
-moz-transition: -moz-transform 1s;
transition: transform 1s;
}
#footerlogo:hover {
-webkit-transform: rotate(360deg);
-moz-transform: rotate(360deg);
transform: rotate(360deg);
}