使用CSS3旋转背景图片 [英] Rotating a background image with CSS3
问题描述
我有一个背景图片,有一个指向右边的箭头。当用户点击按钮时,所选状态将箭头改变为向下(使用我的图片精灵中的不同背景位置)。
I have a background image that has an arrow that points to the right. When a user clicks on the button, the selected state changes the arrow to point down (using a different background position in my image sprite).
是否还有动画使用CSS3,所以一旦按钮被点击和jQuery分配一个选择类,它将旋转动画(只有90度)从右到下? (最好使用带有指向右边的箭头的单个图像/位置)
Is there anyway to animate this using CSS3 so once the button is clicked and jQuery assigns it a "selected" class, it will rotate in an animation (only 90 degrees) from the right to down? (preferably using the single image/position with the arrow that points to the right)
我不确定是否需要使用变换或关键帧动画帧。 / p>
I'm unsure as to whether transform or key animation frames need to be used.
推荐答案
您可以使用:: after(或:: before)伪元素来生成动画
you could use the ::after (or ::before) pseudo-element, to generate the animation
div /*some irrelevant css */
{
background:-webkit-linear-gradient(top,orange,orangered);
background:-moz-linear-gradient(top,orange,orangered);
float:left;padding:10px 20px;color:white;text-shadow:0 1px black;
font-size:20px;font-family:sans-serif;border:1px orangered solid;
border-radius:5px;cursor:pointer;
}
/* element to animate */
div::after /* you will use for example "a::after" */
{
content:' ►'; /* instead of content you could use a bgimage here */
float:right;
margin:0 0 0 10px;
-moz-transition:0.5s all;
-webkit-transition:0.5s all;
}
/* actual animation */
div:hover::after /* you will use for example "a.selected::after" */
{
-moz-transform:rotate(90deg);
-webkit-transform:rotate(90deg);
}
HTML:
<div>Test button</div>
在您的情况下,您将使用element.selected类而不是
in your case you will use element.selected class instead of
jsfiddle demo : http://jsfiddle.net/p8kkf/
希望这有助于
这篇关于使用CSS3旋转背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!