1. 程式人生 > >資訊滾動(marquee+JS實現)

資訊滾動(marquee+JS實現)


Attributes behavior Sets how the text is scrolled within the marquee. Possible values are scrollslide and alternate. If no value is specified, the default value is scroll. bgcolor Sets the background color through color name or hexadecimal value. direction Sets the direction of the scrolling within the marquee. Possible values are 
leftrightupand down. If no value is specified, the default value is left. height Sets the height in pixels or percentage value. width Sets the width in pixels or percentage value. hspace Sets the horizontal margin loop Sets the number of times the marquee will scroll. If no value is specified, the default value is −1, which means the marquee will scroll continuously.
scrollamount Sets the amount of scrolling at each interval in pixels. The default value is 6. scrolldelay Sets the interval between each scroll movement in milliseconds. The default value is 85. Note that any value smaller than 60 is ignored and the value 60 is used instead, unlesstruespeed is specified.
truespeed By default, scrolldelay values lower than 60 are ignored. If truespeed is present, those values are not ignored. vspace Sets the vertical margin in pixels or percentage value. 補充:
  • behavior的預設值為scroll
  • scrollamount 表示運動速度,值是正整數,預設為6,數值越大,移動速度也越快
  • scrolldelay 用於設定兩次滾動操作之間的間隔時間,該時間以毫秒為單位
  • <marquee bgcolor=FF0000>...</marquee> 設定背景顏色
  • <marquee onmouseover="this.stop();" onmouseout="this.start();">...</marquee> 滑鼠移上去就暫停滾動
為什麼<marquee>標籤會被棄用? 因為它違反了W3C的武學道義,W3C江湖第一原則就是功能性分離即行為與表現的分離,只有恪守這個原則的標籤才會被允許參加舞林大會,其他類似於marquee爾等皆是歪門邪道,武功再高也不要,不要!好像就是武功太高啦,哈哈 無縫滾動 var area =document.getElementById("con"); var con1 = document.getElementById("con1"); var con2 = document.getElementById("con2"); con2.innerHTML = con1.innerHTML; function scrollUp() { if (con.scrollTop >= con1.offsetHeight) { con.scrollTop = 0; } else { con.scrollTop ++; } } var myScroll = setInterval("scrollUp()", 30); con.onmouseover = function () { clearInterval(myScroll); } con.onmouseout = function () { myScroll = setInterval("scrollUp()", 30); } 間歇性滾動 // 克隆 var box3con =document.getElementById("box3con"); box3con1.innerHTML += box3con1.innerHTML; function box3scrollUp() { box3con.scrollTop ++; if (box3con.scrollTop % 30 == 0) { clearInterval(box3myScroll); setTimeout(function () { box3con.scrollTop ++; box3myScroll = setInterval(box3scrollUp, 50); }, 2000); } } var box3myScroll = setInterval(box3scrollUp, 50); box3con.onmouseover = function () { clearInterval(box3myScroll); } box3con.onmouseout = function () { box3myScroll = setInterval(box3scrollUp, 50); } <marquee>案例 <div id="box1"> <marquee behavior="" direction="up"> 我是滾動預設up </marquee> <marquee behavior="scroll" direction="down" > 我是滾動behavior="scroll"down </marquee> <marquee behavior="slide" direction="" scrollamount="6" loop="2"> 我是滾動behavior="slide" </marquee> <marquee behavior="scroll" direction="right" scrollamount="10" scrolldelay="0" onmouseover="this.stop();" onmouseout="this.start();"> <p><a href="">我是滾動behavior="scroll"</a></p> </marquee> <!-- "down"與"left"的合成 --> <marquee behavior="scroll" direction="down" width="250" height="150" behavior="alternate" style="border:solid"> <marquee behavior="alternate" direction="left"> This text will bounce </marquee> </marquee> </div>