<marquee> 為 IE 專屬非標準標籤,HTML5 已棄用(Obsolete),但所有主流瀏覽器仍支援。現代網頁建議改用 CSS Animation 或 JavaScript 實現跑馬燈,以符合標準、支援無障礙(可暫停)、效能更佳。本文完整整理 Marquee 所有屬性,供維護舊專案參考,並提供現代替代方案。
| 屬性 | 說明 | 預設值 | 建議值/範例 |
|---|---|---|---|
scrollamount | 每幀移動像素(速度) | 6 | 1~3(平滑),值越大越快 |
scrolldelay | 幀間延遲毫秒(速度反向) | 85 | 通常不設,配合 scrollamount 調整 |
direction | 滾動方向 | left | left、right、up、down |
behavior | 滾動模式 | scroll | scroll(循環)、alternate(來回)、slide(滑入停止) |
width | 容器寬度 | 100% | 像素或百分比,如 300、100% |
height | 容器高度 | 自動 | 垂直滾動必設,如 160 |
loop | 循環次數 | infinite | 數字或 infinite |
bgcolor | 背景色 | 透明 | #FFFFCC |
hspace / vspace | 水平/垂直邊距 | 0 | 像素值 |
onmouseover="this.stop()" | 滑鼠進入停止 | — | 事件屬性,非標準屬性 |
onmouseout="this.start()" | 滑鼠離開繼續 | — | 事件屬性,非標準屬性 |
<marquee scrollamount="2" width="300">公告:系統將於今晚維護</marquee>
<marquee scrollamount="2" width="300">
<a href="https://example.com" target="_blank">點擊查看詳細公告</a>
</marquee>
<marquee scrollamount="2" width="300" onmouseover="this.stop()" onmouseout="this.start()">
重要通知:請詳閱條款...
</marquee>
<marquee scrollamount="2" width="200" behavior="alternate">
歡迎光臨!
</marquee>
<marquee scrollamount="2" width="300" height="160" direction="up">
• 早晨好啊!<br>
• 空氣好清新啊<br>
• 今朝食乜好呢?<br>
• <a href="https://example.com">腳本之家</a>
</marquee>
FrontPage 儲存時會重排 Marquee 屬性順序,導致多行垂直滾動失效(僅顯示第一行)。
<script>
document.write('<marquee scrollamount="2" width="300" height="160" direction="up">'
+ '• 早晨好啊!<br>'
+ '• 空氣好清新啊<br>'
+ '• 今朝食乜好呢?<br>'
+ '• <a href="https://example.com">腳本之家</a>'
+ '</marquee>');
</script>
原理:繞過 FrontPage 對靜態 HTML 的重寫,由 JS 動態輸出完整標籤。
<style>
.marquee-box { overflow: hidden; white-space: nowrap; width: 300px; }
.marquee-content { display: inline-block; padding-left: 100%;
animation: marquee 10s linear infinite; }
@keyframes marquee { to { transform: translateX(-100%); } }
.marquee-box:hover .marquee-content { animation-play-state: paused; }
</style>
<div class="marquee-box">
<span class="marquee-content">公告:系統將於今晚維護,請提前備份資料。</span>
</div>
<style>
.v-marquee { height: 160px; overflow: hidden; position: relative; }
.v-marquee ul { margin: 0; padding: 0; list-style: none;
animation: v-marquee 8s linear infinite; }
.v-marquee li { line-height: 1.6; }
.v-marquee:hover ul { animation-play-state: paused; }
@keyframes v-marquee { to { transform: translateY(-50%); } }
/* 需將內容複製一份接在後面以實現無縫循環,JS 輔助較佳 */
</style>
<div class="v-marquee">
<ul>
<li>早晨好啊!</li>
<li>空氣好清新啊</li>
<li>今朝食乜好呢?</li>
<li><a href="#">腳本之家</a></li>
</ul>
</div>
onmouseover/out,CSS 用 animation-play-state: paused。Marquee 雖簡便但屬非標準棄用技術。新專案請採用 CSS Animation + 無障礙暫停機制;維護舊專案時,掌握完整屬性表與 FrontPage 相容技巧可快速修復問題。技術債務最終仍需透過重構償還。