<marquee> 是 IE 專屬非標準標籤,雖簡單但**不建議在現代專案使用**(無語意、無障礙問題、已從標準移除)。本文整理屬性參考,現代替代方案請見文末。
<marquee scrollamount="2" width="300">滾動文字</marquee>
| 屬性 | 說明 | 建議值 |
|---|---|---|
scrollamount | 每幀移動像素(速度) | 1-3(預設 6 太快) |
scrolldelay | 幀延遲毫秒(速度反向) | 預設 90,通常不需設 |
width / height | 滾動區域寬高 | 垂直滾動必設 height |
direction | 滾動方向 | left(預設)/right/up/down |
behavior | 滾動模式 | scroll(循環)/alternate(來回)/slide(滑入停止) |
loop | 循環次數 | -1無限(預設) |
bgcolor | 背景色 | 十六進位色碼 |
hspace/vspace | 水平/垂直邊距 | 像素值 |
<marquee scrollamount="2" width="300">
<a href="https://example.com">範例連結</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>
• <a href="https://cctv.com">中央電視台</a>
</marquee>
FP 儲存會打亂 <marquee> 內部結構,導致只滾動第一行。解法:將整段代碼包在 document.write() 中輸出。
<script>
document.write('<marquee ...>...</marquee>');
</script>
.marquee {
overflow: hidden; white-space: nowrap; box-sizing: border-box;
}
.marquee span {
display: inline-block; padding-left: 100%;
animation: marquee 10s linear infinite;
}
.marquee:hover span { animation-play-state: paused; }
@keyframes marquee { to { transform: translateX(-100%); } }
推薦成熟庫:Marquee3000、vue-marquee、react-marquee。
⚠️ <marquee> 已從 HTML 標準移除,僅為相容舊站維護。新專案請務必採用 CSS/JS 現代實作。