CSS3动画位置

前端之家收集整理的这篇文章主要介绍了CSS3动画位置前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
考虑使用船舶在蓝色div上方移动的 CSS3动画.由于某种原因,船没有移动. HTML如下:
  1. <div id="wrapper">
  2. <div id="sea">
  3. <img src="ship.png" alt="ship" width="128" height="128"/>
  4. </div>
  5. </div>

为了制作CSS3动画,我使用以下内容

  1. #wrapper { position:relative;top:50px;width:700px;height:320px;
  2. margin:0 auto;background:white;border-radius:10px;}
  3. #sea { position:relative;background:#2875DE;width:700px;height:170px;
  4. border-radius:10px;top:190px; }
  5. #sea img {
  6. position:relative;left:480px;top:-20px;
  7. animation:myship 10s;
  8. -moz-animation:myship 10s; /* Firefox */
  9. -webkit-animation:myship 10s; /* Safari and Chrome */
  10. @keyframes myship {
  11. from {left: 480px;}
  12. to{left:20px;}
  13. }
  14. @-moz-keyframes myship {
  15. from {left: 480px;}
  16. to {left:20px;}
  17. }
  18. @-webkit-keyframes myship {
  19. from {left: 480px;}
  20. to{left:20px;}
  21. }
  22. }

船舶图像没有移动.任何帮助是极大的赞赏.

解决方法

你必须在css选择器之外声明你的关键帧,以及为绝对定位的元素设置动画.

http://jsfiddle.net/aNvSf/

修改过的css看起来像这样:

  1. #wrapper{
  2. position:relative;
  3. top:50px;
  4. width:700px;
  5. height:320px;
  6. margin:0 auto;
  7. background:white;
  8. border-radius:10px;
  9. }
  10. #sea{
  11. position:relative;
  12. background:#2875DE;
  13. width:700px;
  14. height:170px;
  15. border-radius:10px;
  16. top:190px;
  17. }
  18. #sea img{
  19. position:absolute;
  20. left:480px;
  21. top:-20px;
  22. animation:myship 10s;
  23. -moz-animation:myship 10s; /* Firefox */
  24. -webkit-animation:myship 10s; /* Safari and Chrome */
  25. }
  26.  
  27. @keyframes myship{
  28. from {left: 480px;}
  29. to{left:20px;}
  30. }
  31. @-moz-keyframes myship{
  32. from {left: 480px;}
  33. to{left:20px;}
  34. }
  35. @-webkit-keyframes myship{
  36. from {left: 480px;}
  37. to{left:20px;}
  38. }​

猜你在找的CSS相关文章