The rolling of the Japanese website sin100 saw the day before yesterday. After mining, it was originally displayed after reading xml using Ajax.
This is the latest rolling classic topic for your reference.
The example uses the prototype. js ajax Lightweight Framework.
Because the prototype. js file is remotely called, the test friends can wait patiently for a while.
Classic does not allow remote calls to the js files of other sites. Therefore, you must perform one more operation and copy the operation to a local computer to view the result.
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Strict // EN"
Http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd>
<Html xmlns = "http://www.w3.org/1999/xhtml" xml: lang = "gb2312">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Meta name = "author" content = "Smiling doldolphin"/>
<Meta name = "keywords" content = "design, css, cascading, style, sheets, xhtml, graphic design, w3c, web standards, visual, display, java, javascript, c ++, php, jsp, asp, py, pl "/>
<Meta name = "description" content = "my favorites language."/>
<Meta name = "robots" content = "all"/>
<Title> doldolphin Document </title>
<Style type = "text/css" title = "currentStyle" media = "screen">
# Scroll {width: 99%; height: 25px; border: 1px solid #2BBB00; background: # E7FFE0; overflow: hidden ;}
# ScrollFrame, # scrollFrame2 {line-height: 25px; font-size: 13px; word-break: keep-all; line-break: normal; white-space: nowrap ;}
# ScrollFrame span, # scrollFrame2 span {display: inline; margin-right: 20px ;}
</Style>
<Script src = "http://prototype.conio.net/dist/prototype-1.4.0.js" type = "text/javascript"> </script>
</Head>
<Body>
<Div id = "scroll">
<Div id = "scrollFrame"> </div>
<Div id = "scrollFrame2"> </div>
</Div>
<Script language = "javascript" type = "text/javascript">
Var Ticker = Class. create ();
Ticker. prototype = {
Initialize: function (){
Try {
This. scrollType = "normal ";
This. m_scroll = $ (arguments [0]);
This. m_scroll_1 = $ (arguments [1]);
This. m_scroll_2 = $ (arguments [2]);
This. m_speed = (arguments [3] [0])? Arguments [3] [0]: 3;
This. m_request = (arguments [3] [1])? Arguments [3] [1]: 60;
This. m_loop = (arguments [3] [2])? Arguments [2]: 0.05;
This. m_url = (arguments [3] [3])? Arguments [3] [3]: 'http: // bbs.blueidea.com/rss.php? Fid = 1 ';
} Catch (e ){}
Finally {}
Event. observe (this. m_scroll, 'mouseover', this. mouseover. bindAsEventListener (this), false );
Event. observe (this. m_scroll, 'mouseout', this. mouseout. bindAsEventListener (this), false );
New PeriodicalExecuter (this. scroll. bindAsEventListener (this), this. m_loop );
New PeriodicalExecuter (this. load. bindAsEventListener (this), this. m_request );
This. load ();
},
Load: function (){
Var request = new Ajax. Request (
This. m_url,
{
Method: 'post ',
OnSuccess: this. update. bindAsEventListener (this ),
OnFailure: false,
On304: false
}
);
},
Update: function (request ){
Var items = request. responseXML. getElementsByTagName ("item ");
For (var I = 0; I <items. length; I ++ ){
Var title = items [I]. childNodes [0]. childNodes [0]. nodeValue;
Var link = items [I]. childNodes [1]. childNodes [0]. nodeValue;
Var description = items [I]. childNodes [2]. childNodes [0]. nodeValue;
Var author = items [I]. childNodes [4]. childNodes [0]. nodeValue;
This. m_scroll_1.innerHTML + = "<span> <a href = \" "+ link +" \ "title = \" "+ author + ": \ r \ n "+ description +" \ ">" + I + ":" + title + "</a> </span> ";
}
This. m_scroll_2.innerHTML = this. m_scroll_1.innerHTML;
},
Scroll: function (event ){
Switch (this. scrollType ){
Case "slow ":
If (this. m_scroll_2.offsetWidth-this.m_scroll.scrollLeft <= 0 ){
This. m_scroll.scrollLeft-= this. m_scroll_1.offsetWidth;
} Else {
This. m_scroll.scrollLeft ++;
}
Break;
Case "normal ":
Default:
If (this. m_scroll_2.offsetWidth-this.m_scroll.scrollLeft <= 0 ){
This. m_scroll.scrollLeft-= this. m_scroll_1.offsetWidth;
} Else {
This. m_scroll.scrollLeft + = 3;
}
Break;
}
},
Mouseover: function (){
This. scrollType = 'slow ';
Return false;
},
Mouseout: function (){
This. scrollType = 'normal ';
Return false;
}
}
Ticker1 = new Ticker ("scroll", "scrollFrame", "scrollFrame2", [0.05, 'HTTP: // bbs.blueidea.com/rss.php? Fid = 1']);
</Script>
</Body>
</Html>