文字從右向左滑入,完整顯示後自動停止,不重複播放。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>文字滾動自動停止範例</title>
</head>
<body>
<p align="left">
<marquee height="293" behavior="slide" width="550" loop="1"
scrollamount="1" scrolldelay="100">
<font style="font-size: 18pt; font-family: 方正姚體; color: #ea0000">
<strong>代碼滾動</strong>
</font>
</marquee>
</p>
</body>
</html>
| 屬性 | 說明 |
|---|---|
behavior="slide" | 滑入後停止(而非持續捲動 scroll 或來回彈跳 alternate) |
loop="1" | 僅播放一次 |
scrollamount="1" | 每步移動像素(越小越平滑) |
scrolldelay="100" | 每步延遲毫秒(越大越慢) |
<marquee> 為非標準專屬標籤(IE 起源),現代專案建議使用 CSS Animation 或 JavaScript 實現:
@keyframes slide-in {
from { transform: translateX(100%); }
to { transform: translateX(0); }
}
.marquee-text {
animation: slide-in 5s ease-out forwards;
white-space: nowrap;
overflow: hidden;
}
優點:符合標準、可控性強、支援暫停/續播/無障礙屬性。