amp-fx-collection 能幫我實現,所有的願望(誇張了)
今天要講的 amp-fx-collection 可以幫我們在 AMP 的世界中,輕鬆完成視覺效果;ex:視差、淡入。計劃很快支持飛入、……的更多效果。
<script async custom-element="amp-fx-collection" src="https://cdn.ampproject.org/v0/amp-fx-collection-0.1.js"></script>
<div amp-fx="fade-in" data-margin-start="20%"><!-- amp-fx 這 attribute ,為元素指定視覺效果 -->
    <amp-img width="1600" height="900" layout="responsive" src="https://picsum.photos/1600/900?image=1069"></amp-img>
</div>
例如:
<h1 amp-fx="parallax" data-parallax-factor="1.5">
  A title that moves faster than other content.
</h1>
data-parallax-factor
0 及大於 0 的 number ,物件相對於 csolling 頁面時的速度
0 : 物件與頁面一起滾動0 ~ 小於 1 : 元件滾動比 scrolling 慢1 : 正常速度1 : 元件滾動比 scrolling 快例如:
<div amp-fx="fade-in" data-duration="2000ms">
    <amp-img width="1600" height="900" layout="responsive" src="https://picsum.photos/1600/900?image=1069"></amp-img>
</div>
data-duration
data-easing
cubic-bezier(0.40, 0.00, 0.40, 1.00)
linear - 相當於 cubic-bezier(0.00,0.00,1.00,1.00)
easy-in-out - 相當於 cubic-bezier(0.80,0.00,0.20,1.00)
ease-in - 相當於 cubic-bezier(0.80,0.00,0.60,1.00) (預設值)
ase-out - 相當於 `cubic-bezier(0.40,0.00,0.40,1.00)custom-bezier()
data-margin-start
5%
fade-in-scroll - 隨捲動頁面而淡入預設情況下,一旦物件完全可見,我們就不再為不透明度設置動畫。
基本用法:
<div amp-fx="fade-in-scroll" data-repeat>
    <amp-img width="1600" height="900" layout="responsive" src="https://picsum.photos/1600/900?image=1069"></amp-img>
</div>
data-repeat
data-margin-start
0%。data-margin-end
50%。data-duration
data-easing
cubic-bezier(0.40, 0.00, 0.40, 1.00)
fade-in 中的一樣data-margin-start
5%
data-fly-in-distance
| AMP-FX VALUE | MOBILE | TABLET | DESKTOP | 
|---|---|---|---|
| fly-in-bottom | 25% | 25% | 33% | 
| fly-in-top | 25% | 25% | 33% | 
| fly-in-left | 100% | 100% | 100% | 
| fly-in-right | 100% | 100% | 100% | 
例如:
<div amp-fx="fade-in fly-in-bottom" data-duration="1000ms">
    <amp-img width="1600" height="900" layout="responsive" src="https://picsum.photos/1600/900?image=1069"></amp-img>
</div>
但是以下幾個請 不要 做結合
parallax 、 fly-in-top 、 fly-in-bottom
fly-in-left 、 fly-in-right
fade-in 、 fade-in-scroll
參考來源: