<marquee> 你需要知道的事<marquee> 是早期 Internet Explorer 專屬的非標準標籤,用於實現文字或圖片的滾動播放效果。雖然現代 Web 開發推薦使用 CSS Animation 或 JavaScript 實現更可控、標準化的滾動效果,但在維護舊專案、快速原型或特定相容性場景下,了解其完整屬性與行為仍有實用價值。本文整理了所有支援屬性、事件處理、常見樣式與可直接複製的完整範例。
<marquee><font size="+3" color="red">Hello, World</font></marquee>
預設行為:水平向左滾動、無限循環、滑鼠懸停不停止。
| 屬性 | 說明 | 可用值 / 範例 |
|---|---|---|
behavior | 滾動模式 | scroll(預設,循環滾動)、slide(滑入停止)、alternate(來回往復) |
direction | 滾動方向 | left、right、up、down |
scrollamount | 每幀移動像素(速度) | 正整數,如 10、20 |
scrolldelay | 幀延遲毫秒數(平滑度) | 正整數,如 100;過大會產生停頓感 |
loop | 循環次數 | -1(預設,無限)、2(滾動兩次停止) |
width / height | 顯示區域寬高 | 像素或百分比,如 width="500"、height="300" |
bgcolor | 背景顏色 | 十六進位 #FF0000、RGB rgb(255,0,0)、顏色名 red |
align | 內容垂直對齊 | top、middle、bottom、absbottom、absmiddle、baseline、texttop |
hspace / vspace | 水平/垂直邊距 | 像素值,如 hspace="50"、vspace="20" |
最常見的需求是「滑鼠移入停止、移出繼續」:
<marquee
onmouseover="this.stop()"
onmouseout="this.start()">
滑鼠移上停止,移開繼續滾動
</marquee>
this.stop():暫停滾動this.start():恢復滾動<marquee
id="notice"
align="left"
behavior="scroll"
bgcolor="#FF0000"
direction="up"
height="300"
width="200"
hspace="50"
vspace="20"
loop="-1"
scrollamount="10"
scrolldelay="100"
onmouseover="this.stop()"
onmouseout="this.start()">
這是一個完整配置的垂直向上滾動公告欄
</marquee>
<div align="center">
<table border="1" width="206" cellspacing="0" cellpadding="0" height="90">
<tr>
<td valign="top">
<marquee onmouseover="this.stop()" onmouseout="this.start()"
scrollamount="1" scrolldelay="100" direction="up" height="99%">
<table cellspacing="0" cellpadding="0" width="95%" align="center" border="0">
<tbody>
<tr>
<td valign="top" height="120">
<p><font color="#000033">·<a href="#">歡迎您惠臨!</a></font></p>
<p><font color="#000033">·<a href="#">更多劇本代碼...</a></font></p>
<p><font color="#000033">·<a href="#">一個學習型的原始碼網站...</a></font></p>
<p><font color="#000033">·<a href="#">如有建議請提交給我們...</a></font></p>
<p><font color="#000033">·<a href="#">異常感謝大家常常惠顧</a></font></p>
<p><font color="#000033">·<a href="#">再次感謝大家,再見</a></font></p>
</td>
</tr>
</tbody>
</table>
</marquee>
</td>
</tr>
</table>
</div>
以下提供可直接在瀏覽器執行的測試碼,可即時調整屬性觀察效果:
對於新專案,強烈建議使用以下標準化方案:
@keyframes scroll { from { transform: translateX(100%); } to { transform: translateX(-100%); } },效能最佳、GPU 加速、可暫停/反向/響應式。Swiper、Marquee3000(無限無縫跑馬燈)。<marquee> 內部可包含任意流式內容(文字、圖片、表格、連結等)。<marquee> 是一個時代的產物,以極簡單的宣告式語法解決了早期網頁「跑馬燈」需求。掌握其 11 個核心屬性與 2 個關鍵事件,足以應對維護舊系統或快速原型開發。但在現代 Web 應用中,請優先選擇 CSS Animation 或 JavaScript 方案,以獲得更好的效能、無障礙支援與未來相容性。