【问题标题】:CSS animation of scale & color together causes font pixelation比例和颜色的 CSS 动画一起导致字体像素化
【发布时间】:2016-09-22 18:13:06
【问题描述】:

我通过添加一个类来触发font-iconcss 动画。动画缩放图标从1到30,将color#000改为#ff0000

虽然它在 mozilla 中运行良好,但它会使图标缩放,就像它在 chrome、opera 和 safari 中的低质量 png 图像一样。无法检查 ie。

通过在::before伪元素中隔离彩色动画,可以在chrome和opera中修复。

但在 Safari 中,即使只是缩放动画也会将 font-icon 视为 png 图像。

随着动画完成,图标恢复其字体性质,像素化消失。

例子:

  1. 仅适用于 Mozilla http://codepen.io/g1un/pen/Kgrpjq
  2. 适用于 Mozilla、Chrome、Opera http://codepen.io/g1un/pen/BLzoWp

代码,只能在 Mozilla 中正常工作:

<div>
  <h1></h1> 
</div>


div {
  display: flex;
  justify-content: center;
  height: 100vh;
  align-items: center;
}

h1 {
  position: relative;

  font-size: 34px;

  cursor: pointer;
}

h1::before {
  content: 'A';
}

h1.anima {
  animation: anima;
  -webkit-animation: anima;
  animation-duration: 3s;
  -webkit-animation-duration: 3s;
  animation-fill-mode: forwards;
  -webkit-animation-fill-mode: forwards;
}

@-webkit-keyframes anima {
  0% {
      transform: scale(1);
      color: #000;
    }
    100% {
      transform: scale(30);
      color: #ff0000;
    }
}

@keyframes anima {
  0% {
      transform: scale(1);
      color: #000;
    }
    100% {
      transform: scale(30);
      color: #ff0000;
    }
}


$('h1').on('click', function(){
  $(this).addClass('anima');
  var _this = $(this);
  setTimeout(function(){
    _this.removeClass('anima');
  }, 5000);
});

CSS 变化,对 chrome 和 opera 有帮助:

h1.anima::before {
  animation: anima-before;
  -webkit-animation: anima-before;
  animation-duration: 3s;
  -webkit-animation-duration: 3s;
  animation-fill-mode: forwards;
  -webkit-animation-fill-mode: forwards;
}

@-webkit-keyframes anima {
  0% {
      transform: scale(1);
    }
    100% {
      transform: scale(30);
    }
}

@keyframes anima {
  0% {
      transform: scale(1);
    }
    100% {
      transform: scale(30);
    }
}

@keyframes anima-before {
  0% {
      color: #000;
    }
    100% {
      color: #ff0000;
    }
}

@-webkit-keyframes anima-before {
  0% {
      color: #000;
    }
    100% {
      color: #ff0000;
    }
}

有没有人知道更好的方法来制作 chrome 和 opera 动画而无需伪元素破解?谁知道 safari 出了什么问题,以及如何修复像素化缩放?

更新:
正如@ZBerg 在他的评论中提到的那样:“字体平滑选项具有广泛的支持变体。如果某些东西影响了您的桌面配置文件,它可能会产生连锁反应(谷歌 - 屏幕字体的平滑边缘)”。
考虑到我对 chrome 没有更多问题(但确实有它,正如您通过屏幕截图看到的那样,在评论中链接),确实影响了我的桌面(但我不能在谷歌上确切地了解平滑问题而缩放)。
总的来说,我想我的问题的完整答案必须包括:

  • 野生动物园的决定(或解释它有什么问题);
  • (可选)解释 chrome 出了什么问题。

在解释下,我的意思是链接到问题报告或关于 chrome 重现错误的方式。

【问题讨论】:

  • 刚刚在 chrome 和 ffox 中测试过。两者看起来都对我很好。 Win 7. (chrome 版本 53.0.2785.116 m) (ffox 48.0.2)
  • @ZBerg 现在它真的有效了!我没有疯。我在 chrome 中制作了这个 bug 的截图(很遗憾它不是 gif)。 savepic.ru/11445211.png
  • 而且它在 safari (9.1.3 (10601.7.8)) 中仍然不起作用。 gif截图savepic.ru/11464666.gif
  • @ZBerg 我不知道,我的 chrome(与您的版本相同)周五 %)出了什么问题。但是感谢您的测试!
  • 我对此进行了一些研究 -> 显然,字体平滑选项具有广泛的支持变体。如果某些东西影响了您的桌面配置文件,它可能会产生连锁反应(谷歌 - 屏幕字体的平滑边缘)

标签: html css css-animations


【解决方案1】:

对我有用的一个解决方案是缩放父级,在这种情况下为“div”,并​​在他身上进行缩放。 CSS

div.anima {
 animation: anima;
 -webkit-animation: anima;
 animation-duration: 3s;
 -webkit-animation-duration: 3s;
 animation-fill-mode: forwards;
 -webkit-animation-fill-mode: forwards;
}

JS:

$('div').on('click', function(){

如下: updated

【讨论】:

  • 很遗憾,您的变体在 safari 中不起作用。自从上次有问题的更新以来,它对 chrome 来说并不重要。
  • 真的对不起!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
  • 1970-01-01
  • 2021-10-09
  • 1970-01-01
  • 1970-01-01
  • 2018-03-24
相关资源
最近更新 更多