【问题标题】:CSS3 animation not working outside FirefoxCSS3 动画在 Firefox 之外不起作用
【发布时间】:2014-10-28 12:48:42
【问题描述】:

我的网站上有一些按钮可以保存、编辑或删除内容。我希望按钮在悬停时“弹出”,使用 CSS3 动画。它在 Firefox 中运行良好,但在所有其他经过测试的浏览器(IE、Opera、Chrome 和 Safari)中都无法播放动画。它只对不透明度进行过渡。

我在 Google 上搜索过熟悉的问题,但找不到解决方案。你们中有人知道我该如何解决这个问题吗?

这是我的小提琴:http://jsfiddle.net/tqk5a74x/

HTML:

<table>
    <tr>
        <td class="td-buttons" rowspan="2">
            <input type="submit" name="submit" class="action-icon save" value="Save" />
        </td>
    </tr>
</table>

CSS:

.save { background: url('https://cdn0.iconfinder.com/data/icons/gloss-basic-icons-by-momentum/16/save.png') 50% 50% no-repeat; }

.save {
    text-decoration: none;
    border: none;
    margin: 0;
    padding: 0;
    cursor: pointer;
}

.action-icon {
    display:inline-block;
    width:24px;
    height:24px;
    vertical-align: middle;
    text-indent: -9999px;
    white-space: nowrap;
    overflow: hidden;
    opacity:.5;
    -webkit-transition:.2s;
    transition:.2s;
}

.action-icon:hover {
    -webit-animation: hover .2s;
    animation: hover .2s;
    -webkit-transition:.2s;
    transition:.2s;
    opacity:1;
}

@-webkit-keyframes hover {
    0% {-webkit-background-size: 100%;}
    40% {-webkit-background-size: 50%;}
    75% {-webkit-background-size: 120%;}
    100% {-webkit-background-size: 100%;}
}

@keyframes hover {
    0% {background-size: 100%;}
    40% {background-size: 50%;}
    75% {background-size: 120%;}
    100% {background-size: 100%;}
}

谢谢!

【问题讨论】:

    标签: css animation cross-browser


    【解决方案1】:

    你有一个拼写错误:

    .action-icon:hover {
        -webit-animation: hover .2s; /* Missing 'k' in 'webkit'*/
        ....
    }
    

    DEMO

    至于 IE,我不相信 background-size 是可动画的。歌剧,没有线索

    对你的动画做些小改动怎么样?

    @keyframes hover {
        0% {transform: scale(1)}
        40% {transform: scale(0.5)}
        75% {transform: scale(1.2)}
        100% {transform: scale(1)}
    }
    

    DEMO

    .save {
      background: url('https://cdn0.iconfinder.com/data/icons/gloss-basic-icons-by-momentum/16/save.png') 50% 50% no-repeat;
    }
    .save {
      text-decoration: none;
      border: none;
      margin: 0;
      padding: 0;
      cursor: pointer;
    }
    .action-icon {
      display: inline-block;
      width: 24px;
      height: 24px;
      vertical-align: middle;
      text-indent: -9999px;
      white-space: nowrap;
      overflow: hidden;
      opacity: .5;
      -webkit-transition: .2s;
      transition: .2s;
    }
    .action-icon:hover {
      -webkit-animation: hover .2s;
      animation: hover .2s;
      -webkit-transition: .2s;
      transition: .2s;
      opacity: 1;
    }
    @-webkit-keyframes hover {
      0% {
        transform: scale(1)
      }
      40% {
        transform: scale(0.5)
      }
      75% {
        transform: scale(1.2)
      }
      100% {
        transform: scale(1)
      }
    }
    @keyframes hover {
      0% {
        transform: scale(1)
      }
      40% {
        transform: scale(0.5)
      }
      75% {
        transform: scale(1.2)
      }
      100% {
        transform: scale(1)
      }
    }
    <table>
      <tr>
        <td class="td-buttons" rowspan="2">
          <input type="submit" name="submit" class="action-icon save" value="Save" />
        </td>
      </tr>
    </table>

    【讨论】:

    • 哦,哇,这太愚蠢了。谢谢!它现在在 Chrome 中运行良好。但是,它在其他浏览器中不起作用。我应该使用额外的前缀吗?还是应该使用 webkit?
    猜你喜欢
    • 1970-01-01
    • 2014-07-18
    • 2013-05-12
    • 2015-03-05
    • 2013-06-27
    • 1970-01-01
    • 2014-10-01
    • 2015-11-05
    • 1970-01-01
    相关资源
    最近更新 更多