滾動經(jīng)典最新話題[prototype框架]下編寫
更新時間:2006年10月03日 00:00:00 作者:
前天見到sin100看到的那個日本網(wǎng)站的滾動,挖掘后原來是使用Ajax讀取xml后顯示出來的。
就弄了這個滾動經(jīng)典最新話題的供朋友參考參考。
范例使用了prototype.js的ajax輕便型框架。
因為遠程調(diào)用了 prototype.js 這個文件,測試的朋友請耐心等候一下下。
經(jīng)典不允許遠程調(diào)用別的站點的js文件,所以還請多一部操作,復(fù)制到本地運行查看結(jié)果。
<!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 Dolphin" />
<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>Dolphin 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[3][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",[3,60,0.05,'http://bbs.blueidea.com/rss.php?fid=1']);
</script>
</body>
</html>
就弄了這個滾動經(jīng)典最新話題的供朋友參考參考。
范例使用了prototype.js的ajax輕便型框架。
因為遠程調(diào)用了 prototype.js 這個文件,測試的朋友請耐心等候一下下。
經(jīng)典不允許遠程調(diào)用別的站點的js文件,所以還請多一部操作,復(fù)制到本地運行查看結(jié)果。
復(fù)制代碼 代碼如下:
<!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 Dolphin" />
<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>Dolphin 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[3][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",[3,60,0.05,'http://bbs.blueidea.com/rss.php?fid=1']);
</script>
</body>
</html>
相關(guān)文章
Prototype源碼淺析 Enumerable部分之each方法
在javascript中,根本找不到Enumerable的影子,因為這一塊是Prototype作者從Ruby中借鑒過來的。2012-01-01prototype Element學(xué)習(xí)筆記(Element篇三)
上一篇把Element的所函數(shù)都梳理了一遍,下面總結(jié)一下這些函數(shù)的功能,畢竟函數(shù)太多,不分門別類一下還是沒有底。2008-10-10Prototype String對象 學(xué)習(xí)
這個對象里面的方法就是提供了一些字符串操作的工具方法,比較重要的gsub方法,下面做了詳細的注釋,簡單的方法就不說了,一看就明白了。2009-07-07Prototype 學(xué)習(xí) 工具函數(shù)學(xué)習(xí)($A方法)
Prototype 學(xué)習(xí) 工具函數(shù)學(xué)習(xí)($A使用方法)2009-07-07Prototype源碼淺析 String部分(三)之HTML字符串處理
現(xiàn)在,String部分轉(zhuǎn)入具體的關(guān)聯(lián)應(yīng)用,分別對應(yīng)HTML字符串,JSON字符串和HTML中的腳本字符串2012-01-01