1. 程式人生 > 其它 >HTML之marquee(文字滾動)詳解

HTML之marquee(文字滾動)詳解

語法:

<marquee></marquee>

以下是一個最簡單的例子:

程式碼如下:

<marquee><font size=+3 color=red>Hello, World</font></marquee>

下面這兩個事件經常用到:

onMouseOut="this.start()" :用來設定滑鼠移出該區域時繼續滾動

onMouseOver="this.stop()":用來設定滑鼠移入該區域時停止滾動

程式碼如下:

<marquee onMouseOut="this.start()" onMouseOver="this.stop()">onMouseOut="this.start()" :用來設定滑鼠移出該區域時繼續滾動 onMouseOver="this.stop()":用來設定滑鼠移入該區域時停止滾動</marquee>

這是一個完整的例子:

程式碼如下:

<marquee id="affiche" align="left" behavior="scroll" bgcolor="#FF0000" direction="up" height="300" width="200" hspace="50" vspace="20" loop="-1" scrollamount="10" scrolldelay="100" onMouseOut="this.start()" onMouseOver="this.stop()">

這是一個完整的例子

</marquee>

該標籤支援的屬性多達11個:

align

設定<marquee>標籤內容的對齊方式

absbottom:絕對底部對齊(與g、p等字母的最下端對齊)

absmiddle:絕對中央對齊

baseline:底線對齊

bottom:底部對齊(預設)

left:左對齊

middle:中間對齊

right:右對齊

texttop:頂線對齊

top:頂部對齊

程式碼如下:

<marquee align="absbottom">align="absbottom":絕對底部對齊(與g、p等字母的最下端對齊)。 </marquee>
<marquee align="absmiddle">align="absmiddle": 絕對中央對齊。 </marquee>
<marquee align="baseline">align="baseline": 底線對齊。 </marquee>
<marquee align="bottom">align="bottom": 底部對齊(預設)。 </marquee>
<marquee align="left">align="left": 左對齊。 </marquee>
<marquee align="middle">align="middle": 中間對齊。 </marquee>
<marquee align="right">align="right": 右對齊。 </marquee>
<marquee align="texttop">align="texttop": 頂線對齊。 </marquee>
<marquee align="top">align="top": 頂部對齊。 </marquee>

behavior

設定滾動的方式:

alternate: 表示在兩端之間來回滾動。

scroll: 表示由一端滾動到另一端,會重複。

slide:      表示由一端滾動到另一端,不會重複。

程式碼如下:

<marquee behavior="alternate">alternate:表示在兩端之間來回滾動。 </marquee>
<marquee behavior="scroll">scroll:表示由一端滾動到另一端,會重複。</marquee>
<marquee behavior="slide">slide:      表示由一端滾動到另一端,不會重複。</marquee>

bgcolor

設定活動字幕的背景顏色,背景顏色可用RGB、16進位制值的格式或顏色名稱來設定。

程式碼如下:

<marquee bgcolor="#006699">設定活動字幕的背景顏色 bgcolor="#006699"</marquee>
<marquee bgcolor="RGB(10%,50%,100%,)">設定活動字幕的背景顏色 bgcolor="rgb(10%,50%,100%,)"</marquee>
<marquee bgcolor="red">設定活動字幕的背景顏色 bgcolor="red"</marquee>

direction

設定活動字幕的滾動方向

程式碼如下:

<marquee direction="down">設定活動字幕的滾動方向direction="down":向下</marquee>
<marquee direction="left">設定活動字幕的滾動方向direction="left":向左</marquee>
<marquee direction="right">設定活動字幕的滾動方向direction="right":向右</marquee>
<marquee direction="up">設定活動字幕的滾動方向direction="up":向上</marquee>

height

設定活動字幕的高度

程式碼如下:

<marquee height="500" direction="down" bgcolor="#CCCCCC">設定活動字幕的高度height="500"</marquee>

width

設定活動字幕的寬度

程式碼如下:

<marquee width="500" bgcolor="#CCCCCC">設定活動字幕的寬度width="500"</marquee>

hspace

設定活動字幕裡所在的位置距離父容器水平邊框的距離

This controls the horizontal(水平)space around the display box.

程式碼如下:

      <table width="500" border="1" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><marquee hspace="100" bgcolor="#CCCCCC">hspace="100"</marquee></td>
        </tr>
      </table>
vspace

設定活動字幕裡所在的位置距離父容器垂直邊框的距離

This controls the vertical(垂直) space around the display box.

程式碼如下:

<marquee vspace="100" bgcolor="#CCCCCC">hspace="100"</marquee>

loop

設定滾動的次數,當loop=-1表示一直滾動下去,預設為-1

程式碼如下:

<marquee loop="-1" bgcolor="#CCCCCC">我會不停地走。</marquee>
<p>&nbsp;</p>
<marquee loop="2" bgcolor="#CCCCCC">我只走兩次哦</marquee>

scrollamount

設定活動字幕的滾動速度,單位pixels

程式碼如下:

<marquee scrollamount="10" >scrollamount="10" </marquee>
<marquee scrollamount="20" >scrollamount="20" </marquee>
<marquee scrollamount="30" >scrollamount="30" </marquee>

scrolldelay

設定活動字幕滾動兩次之間的延遲時間,單位millisecond(毫秒)

值大了會有一步一停頓的效果

程式碼如下:

<marquee scrolldelay="10" >scrolldelay="10" </marquee>
<marquee scrolldelay="100" > scrolldelay="100"</marquee>
<marquee scrolldelay="1000">scrolldelay="1000" </marquee>
<marquee> ... </marquee>

移動屬性的設定 ,這種移動不僅僅侷限於文字,也可以應用於圖片,表格等等

滑鼠屬性

onMouseOut=this.start() ........滑鼠移出狀態滾動

onMouseOver=this.stop() .........滑鼠經過時停止滾動

方向

<direction=#> #=left, right ,up ,down <marquee direction=left>從右向左移!</marquee>

方式

<bihavior=#> #=scroll, slide, alternate <marquee behavior=scroll>一圈一圈繞著走!</marquee>
<marquee behavior=slide>只走一次就歇了!</marquee>
<marquee behavior=alternate>來回走</marquee>

迴圈

<loop=#> #=次數;若未指定則迴圈不止(infinite) <marquee loop=3 width=50% behavior=scroll>只走 3 趟</marquee>
<marquee loop=3 width=50% behavior=slide>只走 3 趟</marquee>
<marquee loop=3 width=50% behavior=alternate>只走 3 趟!</marquee>

速度

<scrollamount=#> <marquee scrollamount=20>啦啦啦,我走得好快喲!</marquee>

延時

<scrolldelay=#> <marquee scrolldelay=500 scrollamount=100>啦啦啦,我走一步,停一停!</marquee>

外觀(Layout)設定

對齊方式(Align)

<align=#> #=top, middle, bottom <font size=6>
<marquee align=# width=400>啦啦啦,我會移動耶!</marquee>
</font>

底色

<bgcolor=#> #=rrggbb 16 進位制數碼,或者是下列預定義色彩:

Black, Olive, Teal, Red, Blue, Maroon, Navy, Gray, Lime,
Fuchsia, White, Green, Purple, Silver, Yellow, Aqua <marquee bgcolor=aaaaee>顏色!</marquee>

面積

<height=# width=#> <marquee height=40 width=50% bgcolor=aaeeaa>面積!</marquee>

空白

(Margins)<hspace=# vspace=#>
<marquee hspace=20 vspace=20 width=150 bgcolor=ffaaaa align=middle>面積!</marquee>
</P>
<marquee id="iescroller" direction=left height=10 onMouseOut=start(); onMouseOver=stop(); scrollamount=2 scrolldelay=10 scrollleft="0" scrolltop="0" behavior="alternate" bgcolor="#999999" style="color: #ffffff; font-size: 14; font-family: '宋體', 'Arial','Helvetica', 'sans-serif'"title=文字內容> 這是放文字或需要移動的圖片(游標放在這裡時用INSERT命令就可以插入圖片)</marquee> </P>

marquee的滾動屬性引數

從<marquee>開始到</marquee>結束,其中有很多引數,其實,朋友們還是應用得很多了,讓圖片滾動起來,也是經常經常應用的,下面對這個網頁引數的屬性做一些簡單的描述; 滾動引數: 1:方向:DIRECTION left---左(預設) right---右 up------上 down----下 2:方式:BEHAVIOR SCROLL -------環繞滾動(預設) SLIDE---------滾動一次 ALTERNATE-----來回滾動 3:次數:LOOP 當LOOP=-1或LOOP=INFINITE時,則表明文字滾動是無限迴圈(預設) 4:速度:SCROLLDELAY 任意自然整數 5:對齊:ALIGN TOP---------對齊上方 MIDDLE------對齊中部 BOTTOM------對齊下方 6:滑鼠的劃過與離開 onMouseOver=this.stop(); onMouseOut=this.start(); 劃過停止滾動。離開,繼續滾動 有了以上引數。我們就很容易製作出一個logo圖片的任意滾動方式,例如: <marquee width=120 height=200 DIRECTION=up BEHAVIOR=ALTERNATE SCROLLDELAY=120 ALIGN=MIDDLE onMouseOver=this.stop(); onMouseOut=this.start();><a href=http://qjpz.com><img src=http://qjpz.com/bbs/images/logo.gif border=0><marquee> 很容易對照出。這是一個滾動速度為120MM,從下到上碰壁即返回並對齊中間,滑鼠劃過圖示即停止,點選圖示進入〈千嬌論壇〉的一個來回滾動的程式碼。 在背景圖片上做滾動字幕 <TABLE width="500" border=0> <TBODY> <TR> <TD background=背景圖片地址 height=250> <P><MARQUEE scrollAmount=2 scrollDelay=50 direction=up width=200 height=200 behavior=scroll>要滾動的文字</MARQUEE></P></TD></TR></TBODY></TABLE></DIV> 引數設定: a)scrollAmount表示速度,值越大速度越快。如果沒有它,預設為6,建議設為1~3比較好 b)scrollDelay也是用來控制速度的,表示走走停停,預設為90,值越大,速度越慢。通常scrollDelay是不需要設定的。 c)direction很明顯是表示滾動的方向,預設為從右向左:←,因此如果是向左滾動的話不需要次引數。其他可選的值還有right,down,up。滾動方向分別為:right表示→,up表示↑,down表示↓。 d)width和height用來表示滾動區域的大小,width是寬度,height是高度。特別是在做垂直滾動的時候,一定要設height的值。 e)behavior是來控制滾動屬性的,預設為迴圈滾動(scroll),同樣,如果是迴圈滾動的話可以不需要此引數。其他可選的值還有alternate(交替滾動),slide(幻燈片效果,指的是滾動一次,然後停止滾動)。 f)每行字的前後<FONT color=#990066 size=4 face=隸書>和</FONT>用定義每行字的顏色,大小和字型,如果哪項不需要的話,把程式碼去掉就行。

圖片滾動 用<img src=相對路徑/檔名>的語句。並且要注意圖片名不要中文,要注意區分英文大小寫。 圖片做超連結 用<a href=>和</a>把<img>包圍,並且img必須設border=0,否則圖片會出現藍框。

正確的例子如:

<a href=http://www.sina.com.cn/><img src=../../j/01.jpg border=0></a>

其中a href=表示超連結,這是最常用的。練習的方法也很簡單,就是平時用FP或DW做網頁的時候,要多檢視原始碼。 多張圖片排列滾動 通常圖片和圖片之間用<br>(回行)或<p style=margin-top:9>(精確調整圖片間的距離)來連結。也可以把你的圖片先用表格排版,然後把這個表格的所有語句也加入到marquee中,讓這個表格來滾動。 程式碼如:

<script>document.write('<marquee scrollAmount=2 width=340 height=160 direction=up onmouseover=stop() onmouseout=start()><a href=http://www.sina.com.cn/><img src=../../j/01.jpg border=0></a></marquee>')</script>