這是 IE 獨有的 revealTrans 濾鏡效果:頁面載入時,圖片以不同風格的轉場動畫出現。同一張圖換個 transition 編號,就有完全不同的揭曉方式。
<!-- 把如下代碼加入 body 區域中 -->
<script for="window" event="onload" language="vbscript">
image1.filters.item(0).apply()
image1.filters.item(0).transition = 10
image1.style.visibility = ""
image1.filters(0).play(2.0)
image2.filters.item(0).apply()
image2.filters.item(0).transition = 11
image2.style.visibility = ""
image2.filters(0).play(2.0)
</script>
<img src="/images/468_60.gif" border="0" id="image1"
style="visibility:hidden; filter:revealTrans(Duration=4.0, Transition=23);"
width="468" height="60" />
<img src="/images/468_60.gif" border="0" id="image2"
style="visibility:hidden; filter:revealTrans(Duration=4.0, Transition=22);"
width="468" height="60" />
四個步驟缺一不可:
visibility:hidden,圖片在轉場開始前是隱藏的,這一步才讓它進場。這套濾鏡是 IE 5.5 到 IE 9 時期的私有功能,其他瀏覽器完全不支援,IE 11 也已移除。更關鍵的是它綁定了 VBScript——只有 IE 能執行,在跨瀏覽器的環境裡等於整段失效。今天若要做進場動畫,做法是:
/* CSS 動畫版本 */
@keyframes reveal {
from { opacity: 0; transform: translateY(12px); }
to { opacity: 1; transform: none; }
}
.banner{
animation: reveal .6s ease both;
}
.banner:nth-child(2){ animation-delay: .1s }
.banner:nth-child(3){ animation-delay: .2s }
用 CSS animation 或 transition 搭配 Intersection Observer(元素進入視窗時才觸發),效果比濾鏡更流暢,而且所有瀏覽器一致。想看更細緻的轉場,Web Animations API 與 View Transitions API 提供了更多控制。
除了 revealTrans,IE 濾鏡還有 Alpha(透明度)、Blur(模糊)、Shadow(陰影)、FlipH/FlipV(水平/垂直翻轉)、Wave(波紋)等。有趣的是,這些效果今天大多有了標準對應:opacity、filter: blur()、box-shadow、transform: scaleX(-1)。當年為了在 IE 上做出陰影而寫的一大串 filter,現在只是一行 box-shadow。
這段歷史的意義是:瀏覽器私有功能總會被標準取代,寫在 CSS 裡的樣式生命週期比寫在腳本裡的長。能交給 CSS 的,就別用 JS。