将 amp-img 标签用于 gif 动画

Using amp-img tag for gif animations

gif 动画有 <amp-anim> 标签。 但是我发现 <amp-img> 标签可以显示 gif 动画。 我知道 <amp-anim> 标签可以设置占位符,但我不需要它。 我再也没有发现任何差异。
所以,我的问题是 "Is there problem to use <amp-img> tag for gif animations?"

打开 https://ampbyexample.com/playground/ 并粘贴下面的 html 代码,如果您想检查 <amp-img> 标签和 <amp-anim> 标签是如何工作的。

<!doctype html>
<html ⚡>
<head>
  <meta charset="utf-8">
  <script async src="https://cdn.ampproject.org/v0.js"></script>
  <script async custom-element="amp-anim" src="https://cdn.ampproject.org/v0/amp-anim-0.1.js"></script>
  <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
  <link rel="canonical" href="https://ampbyexample.com/components/amp-anim/">
  <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-ms-animation:-amp-start 8s steps(1,end) 0s 1 normal both;animation:-amp-start 8s steps(1,end) 0s 1 normal both}@-webkit-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-moz-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-ms-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@-o-keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}@keyframes -amp-start{from{visibility:hidden}to{visibility:visible}}</style><noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
</head>
<body>

  <h2>amp-anim supports gif animation</h2>
  <amp-anim width="245" height="300" src="/img/gopher.gif" alt="an animation"
            attribution="The Go gopher was designed by Reneee French and is licensed under CC 3.0 attributions.">
  </amp-anim>

  <h2>amp-img also supports gif animation</h2>
  <amp-img width="245" height="300" src="/img/gopher.gif" alt="an animation"
            attribution="The Go gopher was designed by Reneee French and is licensed under CC 3.0 attributions.">
  </amp-img>
</body>
</html>

您可以在 amp-anim docs 中了解到 amp-anim 是 amp-img 的扩展版本,因为它提供了额外的功能,特别是考虑到 GIF 动画。只要 amp-img 对您有用,就一定要使用它。

The amp-anim component is very similar to the amp-img element, and provides additional functionality to manage loading and playing of animated images such as GIFs.

amp-animamp-img 之间的唯一区别是 performance: amp-anim is able to reduce CPU usage when the animation is off-screen