1. 程式人生 > >html之marquee實現圖片文字滾動效果詳解

html之marquee實現圖片文字滾動效果詳解

               

在製作網頁的時候,很多情況下會遇到需要某一個文字或者圖片像廣告那樣水平或者垂直的滾動,這樣的效果

JavaScript可以製作,但是比較麻煩,直接看那些程式碼會感覺到非常的複雜。這裡我們來介紹一種簡單的方式實現這

效果,他就是HTML標籤中的marquee,他其實是一個容器標籤。

該標籤不是HTML3.2的一部分,並且只支援MSIE3以後核心,所以如果你使用非IE核心瀏覽器(如:Netscape)可能

無法看到下面一些很有意思的效果

該標籤是個容器標籤

語法:

<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>