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

2016-02-19 12:01 2 1 收藏

有了下面这个滚动经典最新话题[prototype框架]下编写教程,不懂滚动经典最新话题[prototype框架]下编写的也能装懂了,赶紧get起来装逼一下吧!

【 tulaoshi.com - Web开发 】

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

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

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

!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" /
    titleDolphin 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;iitems.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 += "spana href=""+link+"" title=""+author+":rn"+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

来源:https://www.tulaoshi.com/n/20160219/1599533.html

延伸阅读
在.NET下编写中文代码程序 郑佐2005-3-9 一年前,有一次在用Access数据库编程的时候,通过VS.NET数据设计器向导生成数据层代码,查看生成的代码,发现有许多中文,原来数据库中的表名和字段名用的就是中文,程序正常运行,查看相关文档才知道原来VS.NET默认的编码是UTF-8。不久前在一篇blog上看到讲易语言,所以干脆用VS.NET写一些中文代码来...
标签: Web开发
一直没有没有时间看prototype,现在好了,已经更新到了1.5 pre1,呵呵,强大的功能不得不学习啊,这个是提升自己JS能力的又一个捷径. 1. Prototype是什么? 或许你还没有用过它, prototype.js 是一个由Sam Stephenson写的JavaScript包。这个构思奇妙编写良好的一段兼容标准的一段代码将承担创造胖客户端, 高交互性WEB应用程序的重...
大概一年前,我们还在预测视差滚动能否成为趋势,现在,视差滚动网站已经纷繁多样了,到处都有它的影子,除了新奇的体验,网站的纵深感也令人置身其中。在5月份的时候,优设推荐了一篇视差滚动指南,当下是让它真正大展身手的时候了,对这个技术感兴趣的同学移步。 今天推荐的视差滚动网站有点特别,是纵横向兼有的,还包括了flickr、tumblr、...
用VB编写入侵监听程序(下) 程序的代码以及说明如下: ‘本程序在VB6.0+Windows2000下测试通过! DimtmpstrAsString DimNOW_OUTAsInteger'总共出去连接的有几个Winsock PrivateSubCommand1_Click() ListPorts.AddItemtxtADDPORT.Text EndSub PrivateSubCommand2_Click() OnErrorResumeNext ...
标签: Web开发
  做视频点播时,笔者一直想找一个Dreamweaver 3的插件,在网上搜索了一段时间没有找到,只好自己编写。经过对DW3插件和realplay播放器进行认真分析后,笔者用javascript编了一插件,多次测试后使用正常,现总结成文,与大家分享。 插件组成 插件包含三个部分,分别介绍如下: realplay.gif:使用Photoshop制作,大小...

经验教程

593

收藏

12
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部