萬盛學電腦網

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

Dreamweaver 製作跑馬燈(Marquee)完整教學:從基礎到多行垂直滾動

FrontPage 雖有跑馬燈元件,但僅支援單行;Dreamweaver 需手寫代碼,卻能實現多行、垂直、交替、滑鼠暫停等豐富效果。建議用記事本編輯原始碼以防 FrontPage 破壞結構。

基礎語法與參數詳解

<marquee scrollAmount="2" width="300">跑馬燈文字</marquee>
屬性說明建議值
scrollAmount移動速度(像素/幀),值越大越快1~3(預設 6 太快)
width / height顯示區域寬高,垂直滾動必設 height視版面而定
direction滾動方向left(預設)/right/up/down
scrollDelay幀延遲(毫秒),值越大越慢預設 90,通常不需調整
behavior滾動模式scroll(預設循環)/alternate(來回)/slide(滑入停止)

常見效果實作

1. 加入超連結

<marquee scrollAmount="2" width="300">
  <a href="https://www.cctv.com">中央電視台</a>
</marquee>

2. 滑鼠懸停暫停

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

3. 來回交替滾動

<marquee scrollAmount="2" width="99" behavior="alternate">
  文字內容
</marquee>

4. 多行文字向上滾動(公告欄常用)

<marquee scrollAmount="2" width="300" height="160" direction="up">
  ·早晨好啊!<br>
  ·空氣好清新啊<br>
  ·今朝食乜好呢?<p>
  ·<a href="https://www.cctv.com">中央電視台</a>
</marquee>

避坑指南:FrontPage 會破壞多行結構

若頁面曾用 FrontPage 儲存,<marquee> 內部標籤順序會被重排,導致只滾動第一行。解決辦法:將完整 <marquee> 區塊包裹在 document.write() 中輸出:

<script>
document.write('<marquee scrollAmount="2" width="300" height="160" direction="up">'
  + '·早晨好啊!<br>'
  + '·空氣好清新啊<br>'
  + '·今朝食乜好呢?<p>'
  + '·<a href="https://www.cctv.com">中央電視台</a>'
  + '</marquee>');
</script>

結論:HTML 標籤可自由組合,<marquee> 仍是簡單跑馬燈的輕量選擇,但現代專案建議改用 CSS Animation 或 JavaScript 實現更佳控制與無障礙支援。

copyright © 萬盛學電腦網 all rights reserved