首页 > 新闻系统 > 编程天地 > 文章正文

javascrpt实现间隔性滚动的效果

2008-04-09 10:20:11 来源:中国自学编程网 作者:未知 点击:

用法很简单:
var scroll = new ScrollText("content","pre","next",true);
第一个参数是滚动区的id,第二个是显示上一条的按钮的id,第三个是显示下一条的按钮的id,第四个是是否直接开始滚动,为false的话后面再scroll.Start()就OK了。
废话不说了,贴代码吧。
我第一次发贴,不懂排版,直接贴了。
ScrollText.js


function ScrollText(content,btnPrevious,btnNext,autoStart)
{
    this.Speed = 10;
    this.Timeout = 1500;
    this.LineHeight = 20;
    this.NextButton = this.$(btnNext);
    this.PreviousButton = this.$(btnPrevious);
    this.ScrollContent = this.$(content);
    this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
    this.NextButton.onclick = this.GetFunction(this,"Next");
    this.PreviousButton.onclick = this.GetFunction(this,"Previous");
    
    this.NextButton.onmouseover = this.GetFunction(this,"Stop");
    this.NextButton.onmouseout = this.GetFunction(this,"Start");
    
    this.ScrollContent.onmouseover = this.GetFunction(this,"Stop");
    this.ScrollContent.onmouseout = this.GetFunction(this,"Start");
    
    this.PreviousButton.onmouseover = this.GetFunction(this,"Stop");
    this.PreviousButton.onmouseout = this.GetFunction(this,"Start");
    if(autoStart)
    {
        this.Start();
    }
}

ScrollText.prototype.$ = function(element)
{
    return document.getElementById(element);
}

ScrollText.prototype.Previous = function()
{
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("up");
}

ScrollText.prototype.Next = function()
{
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("down");
}

ScrollText.prototype.Start = function()
{
    this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
  
}
ScrollText.prototype.Stop = function()
{
    clearTimeout(this.AutoScrollTimer);
}
ScrollText.prototype.AutoScroll = function()
{
    this.ScrollContent.scrollTop++;
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
    {
        this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Speed);
    }
    else
    {
        if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
        {
            this.ScrollContent.scrollTop = 0;
        }
        this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
    }
}
9 7 3 1 2 4 8 :

相关文章:

    无相关新闻
    无相关新闻

精彩推荐
焦点大图推荐
本类热门文章

论坛美图

广告联系 | 版权说明 | 意见建议 | 加入收藏 | 军网站群 [ 军软件园 - 军软件商城 - 军软件园论坛 ]

电信与信息服务业务经营许可证:京ICP证050203