CSS3动画位置

考虑 CSS3 动画,船舶在蓝色 div 上方移动。由于某种原因,船没有移动。HTML 如下:

考虑 CSS3 动画,船舶在蓝色 div 上方移动。由于某种原因,船没有移动。HTML 如下:

<div id="wrapper">
  <div id="sea">
    <img src="ship.png" alt="ship" width="128" height="128"/>
  </div>
</div>

为了使 CSS3 动画我使用以下内容:

#wrapper { position:relative;top:50px;width:700px;height:320px;
          margin:0 auto;background:white;border-radius:10px;}
#sea { position:relative;background:#2875DE;width:700px;height:170px;
       border-radius:10px;top:190px; }
#sea img { 
  position:relative;left:480px;top:-20px;
  animation:myship 10s;
  -moz-animation:myship 10s; /* Firefox */
  -webkit-animation:myship 10s; /* Safari and Chrome */
  @keyframes myship {
    from {left: 480px;} 
    to{left:20px;} 
   }
   @-moz-keyframes myship {
     from {left: 480px;} 
     to {left:20px;} 
   }
   @-webkit-keyframes myship {
     from {left: 480px;} 
     to{left:20px;} 
   }
}

船的图像没有移动。非常感谢任何帮助。

11

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

http://jsfiddle.net/aNvSf/

你修改的 CSS 看起来像这样:

#wrapper{
    position:relative;
    top:50px;
    width:700px;
    height:320px;
    margin:0 auto;
    background:white;
    border-radius:10px;
}
#sea{
    position:relative;
    background:#2875DE;
    width:700px;
    height:170px;
    border-radius:10px;
    top:190px;
}
#sea img{
    position:absolute;
    left:480px;
    top:-20px;
    animation:myship 10s;
    -moz-animation:myship 10s; /* Firefox */
    -webkit-animation:myship 10s; /* Safari and Chrome */               
}
@keyframes myship{
    from {left: 480px;} 
    to{left:20px;} 
}
@-moz-keyframes myship{
    from {left: 480px;} 
    to{left:20px;} 
}
@-webkit-keyframes myship{
    from {left: 480px;} 
    to{left:20px;} 
}​
3

要使用lefttopbottomright设置动画,必须有一个绝对定位或浮动的元素。因此,将位置更改为absolute

此外,在开始声明关键帧之前,还有未闭合的大括号}

#sea img { 
    position:absolute;
    /* ... */
}

大括号错误:

    #sea img{
         position:absolute; /* absolute */
         left:480px;top:-20px;
         animation:myship 10s;
        -moz-animation:myship 10s; /* Firefox */
        -webkit-animation:myship 10s; /* Safari and Chrome */
    } 
 /* ^ You have to close the braces here, before declaring the keyframes.

下面是一个工作demo

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(652)
我们如何在Google日历API响应中区分辅助日历和共享日历
上一篇
如何从批处理文件创建空文本文件 (create windows batch file)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(51条)