function StartMarquee (lh,speed,delay,index) { /* Parameters for function StartMarquee: LH: The distance or height at which text scrolls up at a time; Speed: rolling speed; Delay: The time interval of rolling pause; Index: The encapsulated function can be applied to different elements in the page; */ var T; var P=false; var O=document.getelementbyid ("Marqueebox" +index); Gets the scrolling area object in the document, assigned to the variable o; o.innerhtml+=o.innerhtml; The actual contents of the object were copied in one copy, containing two UL, of course Li Tag Also From the original 3 lines, to 6 lines; The purpose of the copy is to provide a transition for the text to scroll continuously up. O.onmouseover=function () {p=true} Mouse over, stop scrolling; O.onmouseout=function () {P=false} The mouse leaves and starts scrolling; P is true or false directly affects the execution of the start () function below; o.scrolltop = 0; The distance between the top of the text content and the top of the scrolling area, with an initial value of 0; function Start () { T=setinterval (Scrolling,speed); Every once in a while, SetInterval will perform a scrolling function; The larger the speed, the greater the scrolling time interval, the slower the scrolling speed; if (!p) {o.scrolltop + = 1;} Scrolling stops or starts, depending on the boolean value of the p coming; } function scrolling () { if (o.scrolltop%lh!=0) { If it is not divided evenly, that is, the height of the move up is not up to LH, the content will continue to scroll up; O.scrolltop + 1; if (O.SCROLLTOP>=O.SCROLLHEIGHT/2) o.scrolltop = 0; The content in object o is copied once before, so its scrolling height is actually twice times the height of the original content; When the content scrolls up to the height of the SCROLLHEIGHT/2, all 3 lines of text have been displayed, so that the whole piece ScrollTop 0, and then wait for the next round of rolling, so as to achieve the text uninterrupted upward scrolling effect; }else{ Clearinterval (t); Otherwise clear T, pause scrolling SetTimeout (Start,delay); After delay interval, start start () and scroll continuously } } SetTimeout (Start,delay); Start scrolling for the first time; settimeout executes the function start () after a certain time, and executes only once } Passing parameters StartMarquee (25,30,3000,0); With pause effect StartMarquee (25,40,0,1); Uninterrupted continuous |