【问题标题】:Rotating css not working in chrome旋转css在chrome中不起作用
【发布时间】:2021-01-18 22:08:08
【问题描述】:

好的,所以,我编写了一个代码,我正在寻找一个图像,永远旋转并且它可以工作,但只有在 Firefox 中,它在 chrome 中不起作用,有人可以帮忙吗?

代码:

<div align="left" class="header">
<img src="http://files.enjin.com/177852/SD/PortalHeaderContinuous1.png" class="header2" style="position:fixed; z-index:50; margin-left:-120px; margin-top:20px;">
</div>

<style>

.header2{

animation: rotate 5s linear 0s infinite;
-webkit-animation: rotate 1s linear 0s infinite;
}

@keyframes rotate
{
0%   {}
100% {-webkit-transform: rotate(-360deg);
-moz-transform: rotate(-360deg);
transform: rotate(-360deg);}
}

</style>

【问题讨论】:

    标签: css google-chrome firefox


    【解决方案1】:

    将您的 CSS 更改为:

     .header2{
        -webkit-animation:rotate 4s linear infinite;
        -moz-animation:rotate 4s linear infinite;
        animation:rotate 4s linear infinite;
     }
    
     @-moz-keyframes rotate { 100% { -moz-transform: rotate(360deg); } }
     @-webkit-keyframes rotate { 100% { -webkit-transform: rotate(360deg); } }
     @keyframes rotate { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
    

    点赞this fiddle

    CSS

    div{
        display:inline-block;
    }
    .parent{
        border:1px solid grey;
    }
    .child{
        height:100px;
        width:100px;
        border-radius:9px;
        background:blue;
        margin:10px;
    }
    
    .rotate {
        -webkit-animation:rotate 4s linear infinite;
        -moz-animation:rotate 4s linear infinite;
        animation:rotate 4s linear infinite;
    }
    @-moz-keyframes rotate { 100% { -moz-transform: rotate(360deg); } }
    @-webkit-keyframes rotate { 100% { -webkit-transform: rotate(360deg); } }
    @keyframes rotate { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
    

    HTML

    <div class='parent'>
        <div class='child'>
        </div>    
    </div>
    <a id='rotate' href='#'>Rotate</a>
    

    jQuery

    $('#rotate').click(function(){
       $('.child').addClass('rotate');
    });
    

    【讨论】:

      【解决方案2】:

      您也需要 Keyframes 的前缀,因此将您的 CSS 更改为:

      @keyframes rotate
       {
       0%   {}
       100% {transform: rotate(-360deg);}
       }
      @-webkit-keyframes rotate
       {
       0%   {}
       100% {-webkit-transform: rotate(-360deg);}
      }
      

      演示http://jsfiddle.net/phk24/2/

      【讨论】:

      • 感谢您,我在阅读本文之前发现了缺失的内容,但您的回答是正确的,无论如何,谢谢:)
      猜你喜欢
      • 1970-01-01
      • 2014-04-18
      • 2015-03-30
      • 1970-01-01
      • 2015-07-28
      • 2013-07-25
      • 1970-01-01
      • 2011-11-03
      • 2015-03-31
      相关资源
      最近更新 更多