首页 >web前端 >js教程 >滚动经典最新话题[prototype框架]下编写_prototype

滚动经典最新话题[prototype框架]下编写_prototype

WBOY
WBOY原创
2016-05-16 19:25:49918浏览

前天见到sin100看到的那个日本网站的滚动,挖掘后原来是使用Ajax读取xml后显示出来的。

就弄了这个滚动经典最新话题的供朋友参考参考。
范例使用了prototype.js的ajax轻便型框架。
因为远程调用了 prototype.js 这个文件,测试的朋友请耐心等候一下下。

经典不允许远程调用别的站点的js文件,所以还请多一部操作,复制到本地运行查看结果。

复制代码 代码如下:

nbsp;html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


    
    
    
    
    
    Dolphin Document

    
    <script></script>



    

    


<script> <br><br>var Ticker = Class.create(); <BR>Ticker.prototype = { <BR> initialize: function() { <BR> try{ <BR> this.scrollType = "normal"; <BR> this.m_scroll = $(arguments[0]); <BR> this.m_scroll_1 = $(arguments[1]); <BR> this.m_scroll_2 = $(arguments[2]); <BR> this.m_speed = (arguments[3][0])?arguments[3][0]:3; <BR> this.m_request = (arguments[3][1])?arguments[3][1]:60; <BR> this.m_loop = (arguments[3][2])?arguments[3][2]:0.05; <BR> this.m_url = (arguments[3][3])?arguments[3][3]:'http://bbs.blueidea.com/rss.php?fid=1'; <BR> }catch(e){} <BR> finally{} <BR> Event.observe(this.m_scroll, 'mouseover', this.mouseover.bindAsEventListener(this), false); <BR> Event.observe(this.m_scroll, 'mouseout', this.mouseout.bindAsEventListener(this), false); <BR> new PeriodicalExecuter(this.scroll.bindAsEventListener(this), this.m_loop); <BR> new PeriodicalExecuter(this.load.bindAsEventListener(this), this.m_request); <BR> this.load(); <BR> }, <BR> load:function(){ <BR> var request = new Ajax.Request( <BR> this.m_url, <BR> { <BR> method: 'post', <BR> onSuccess: this.update.bindAsEventListener(this), <BR> onFailure: false, <BR> on304: false <BR> } <BR> ); <BR> }, <BR> update:function(request){ <BR> var items = request.responseXML.getElementsByTagName("item"); <BR> for(var i=0;i<items.length;i++){ <br><br> var title = items[i].childNodes[0].childNodes[0].nodeValue; <BR> var link = items[i].childNodes[1].childNodes[0].nodeValue; <BR> var description = items[i].childNodes[2].childNodes[0].nodeValue; <BR> var author = items[i].childNodes[4].childNodes[0].nodeValue; <BR> this.m_scroll_1.innerHTML += "<span><a href=\""+link+"\" title=\""+author+": \n"+description+"\">"+i+":"+title+""; <BR> } <BR> this.m_scroll_2.innerHTML = this.m_scroll_1.innerHTML; <BR> }, <BR> scroll:function(event){ <BR> switch(this.scrollType){ <BR> case "slow": <BR> if(this.m_scroll_2.offsetWidth-this.m_scroll.scrollLeft<=0){ <BR> this.m_scroll.scrollLeft -= this.m_scroll_1.offsetWidth; <BR> }else{ <BR> this.m_scroll.scrollLeft++; <BR> } <BR> break; <BR> case "normal": <BR> default: <BR> if(this.m_scroll_2.offsetWidth-this.m_scroll.scrollLeft<=0){ <BR> this.m_scroll.scrollLeft -= this.m_scroll_1.offsetWidth; <BR> }else{ <BR> this.m_scroll.scrollLeft+=3; <BR> } <BR> break; <BR> } <BR> }, <BR> mouseover:function(){ <BR> this.scrollType = 'slow'; <BR> return false; <BR> }, <BR> mouseout:function(){ <BR> this.scrollType = 'normal'; <BR> return false; <BR> } <BR>} <BR>ticker1 = new Ticker("scroll","scrollFrame","scrollFrame2",[3,60,0.05,'http://bbs.blueidea.com/rss.php?fid=1']); <br><br></script>




声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn