Why is my CSS3 animation not working in Chrome or

2020-08-04 10:04发布

问题:

I'm using a translate animation, but it doesn't work in Safari or Chrome. What am I doing wrong?

Here's my code, and a JSFiddle of it in action:

HTML

<div id="animate"></div>

CSS

#animate {
  position: absolute;
  top: 100px;
  left: 30px;
  width: 100px;
  height: 100px;
  border-radius: 10%;
  background: gray;
  -webkit-animation:move 6s ease infinite;
  -moz-animation:move 6s ease infinite;
  animation: move 6s ease infinite;
}

@keyframes move {
  50% {
    transform: translate(800px, 0px);
  }
}
@-webkit-keyframes move {
  50% {
    transform: translate(800px, 0px);
  }
}

@-moz-keyframes move {
  50% {
    transform: translate(800px, 0px);
  }
}

回答1:

Webkit still needs the -webkit prefix for transform:

@-webkit-keyframes move {
   50% {
     -webkit-transform: translate(800px, 0px);
  }
}

Demo: http://jsfiddle.net/MLhYS/3/