有这个CSS3代码:
#box1
{
position: relative;
width: 300px;
border: 1px solid black;
box-shadow: -3px 8px 34px #808080;
border-radius: 20px;
box-shadow: -8px 5px 5px #888888;
right: 700px;
top: -200px;
height: 150px;
}
@-webkit-keyframes myfirst {
0% { right:700px; top:-200px;background: yellow;}
50% {background:blue; right:700px; top:200px;}
100% { right:700px; top:-200px; background: yellow}
}
#stam {
font-size: large;
background: green;
width: 100px;
top: 400px;
position: absolute;
}
#stam:hover ~ #box1 { -webkit-animation:myfirst 2s; }
您可以在此处查看代码的工作原理:http://jsfiddle.net/FLe4g/2/
我的问题是:我怎么能做动画所以当我把鼠标放在“stam”div上时,动画将停留在动画的“50%”( 50% {background:blue; right:700px; top:200px;})
上,并且只有当我移动鼠标时“stam”div,动画继续吗?我真的更喜欢解决方案是CSS3而不是js ...谢谢!
答案 0 :(得分:0)
对于向后动画我使用过渡,所以当你前进时你使用动画帧,当你向后移动时你使用过渡:
#box1
{
position: relative;
width: 300px;
border: 1px solid black;
box-shadow: -3px 8px 34px #808080;
border-radius: 20px;
box-shadow: -8px 5px 5px #888888;
right: 300px;
top: -200px;
height: 150px;
-webkit-transition: all 2s;
}
@-webkit-keyframes myfirst {
0% { right:300px; top:-200px;background: yellow;}
100% {background:blue; right:500px; top:200px;}
}
#stam {
font-size: large;
background: green;
width: 100px;
top: 400px;
position: absolute;
}
#stam:hover ~ #box1 {
-webkit-transition: all 0s;
background:blue; right:500px; top:200px;
-webkit-animation:myfirst 2s;
-webkit-animation-fill-mode: forwards;
}