Dom*_*que 9 html css background css3 css-transitions
我想做一个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);
}
Run Code Online (Sandbox Code Playgroud)
我希望这是可能的!我知道它在JS(jQuery)中很容易实现:
$('#something').hover(function(){morecodehere});
Run Code Online (Sandbox Code Playgroud)
...但我想知道是否有可能只用CSS(3)
HTML:
<div id="footerLogo">
<img src="carenza.png"/>
</div>
Run Code Online (Sandbox Code Playgroud)
当然可以,尝试这样的事情:
HTML
<div id="planet">
</div>
Run Code Online (Sandbox Code Playgroud)
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);}
}
Run Code Online (Sandbox Code Playgroud)
我不认为您可以将变换应用于背景图像本身(与div分开.)但是,您可以旋转整个div,包括使用过渡来为其设置动画(这是一个工作示例.)
如果你能描述你想要达到的确切效果,它可能会有所帮助吗?
码:
#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);
}
Run Code Online (Sandbox Code Playgroud)