Safari / Chrome浏览器中的动画速度不变

时间:2019-05-13 10:39:44

标签: javascript html ios css mobile-safari

我正在使用关键帧动画旋转圆。在android浏览器,chrome和Mozilla中运行正常。但是在iPhone的Safari / Chrome浏览器中,单击按钮时的动画速度不会改变。

class App extends React.Component{
    state = {
      speedClass : "two"
    };
    
    render(){
        return(
           <div>
               <div className={"spinMe " + this.state.speedClass}>I am spinning</div>
               <button onClick={this.handleClick}>Change speed</button>
           </div>
        );
    }
    
    handleClick=()=>{
      this.setState({ speedClass: this.state.speedClass === "two"?"one":"two" });
    }
}

ReactDOM.render(
  <App/>,
  document.getElementById("root")
);
.spinMe{
  width:100px;
  height:100px;
  border-radius:50%;
  border:1px solid red;
  display:flex;
  justify-content:center;
  align-items:center;
}

.spinMe.one {
    -moz-animation: spin 1s infinite linear;
    -webkit-animation: spin 1s infinite linear;
    -o-animation: spin 1s infinite linear;
     animation: spin 1s infinite linear;
  }

.spinMe.two {
    -moz-animation: spin 2s infinite linear;
    -webkit-animation: spin 2s infinite linear;
    -o-animation: spin 2s infinite linear;
     animation: spin 2s infinite linear;
  }
}

@-webkit-keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  to {
    -webkit-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@-moz-keyframes spin {
  from {
    -webkit-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  to {
    -webkit-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@-o-keyframes spin {
 from {
    -webkit-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  to {
    -webkit-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}

@keyframes spin {
 from {
    -webkit-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    -moz-transform: rotate(0deg);
    -o-transform: rotate(0deg);
    transform: rotate(0deg);
  }

  to {
    -webkit-transform: rotate(360deg);
    -ms-transform: rotate(360deg);
    -moz-transform: rotate(360deg);
    -o-transform: rotate(360deg);
    transform: rotate(360deg);
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<div id="root"></div>

我找不到任何解决方案,请帮助我解决此问题。在iPhone中,速度不起作用。可能是什么问题?

1 个答案:

答案 0 :(得分:0)

为解决此问题,我两次添加了相同的关键帧动画。在单击时,我切换了动画,它才起作用!