萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> Dreamweaver 教學

Dreamweaver 製作跑馬燈滾動字幕完整屬性與範例指南

<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水平/垂直邊距像素值

常見效果範例

1. 超連結跑馬燈

<marquee scrollamount="2" width="300">
  <a href="https://example.com">範例連結</a>
</marquee>

2. 滑鼠懸停暫停

<marquee scrollamount="2" width="300" onmouseover="this.stop()" onmouseout="this.start()">
  文字內容
</marquee>

3. 來回滾動

<marquee scrollamount="2" width="200" behavior="alternate">來回滾動</marquee>

4. 多行向上滾動 (公告欄)

<marquee scrollamount="2" width="300" height="160" direction="up">
  • 早晨好!<br>
  • 空氣好清新<br>
  • <a href="https://cctv.com">中央電視台</a>
</marquee>

5. 相容 FrontPage 破壞代碼順序的解法

FP 儲存會打亂 <marquee> 內部結構,導致只滾動第一行。解法:將整段代碼包在 document.write() 中輸出。

<script>
document.write('<marquee ...>...</marquee>');
</script>

現代標準替代方案

CSS Animation (純樣式、無障礙、效能佳)

.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%); } }

JavaScript IntersectionObserver (進入視窗才啟動、支援暫停/續播、垂直/水平、無障礙)

推薦成熟庫:Marquee3000、vue-marquee、react-marquee。

⚠️ <marquee> 已從 HTML 標準移除,僅為相容舊站維護。新專案請務必採用 CSS/JS 現代實作。
copyright © 萬盛學電腦網 all rights reserved