求div里js滚动遇到的问题. 代码是文字滚动从下向上滚动.

chenxhcc 2009-04-14 11:25:41
<div id="latest_site_news" class="colbox">
<h3> <!-- {if $site_news.info.page_count gt 1} --> <em class="more"> <a href="{url src=index.php?app=article&act=site_news}">{$lang.more} </a> </em> <!-- {/if} -->{$lang.site_news} </h3>
<div id="news_scroll_bar" style="overflow:hidden; height:180px;">
<div id="news_scroll_items" class="colboxcontent">
<ul>
<!-- {foreach from=$site_news.data item=article} -->
<li> <a href="{url src=index.php?app=article&act=site_news&id=$article.article_id}">{$article.title|escape} </a> </li>
<!-- {/foreach} -->
</ul>
</div>
<div id="news_scroll_replaces" class="colbtm"> </div>
</div>
</div>
<script language="javascript">
var news_scroll_bar = document.getElementById("news_scroll_bar");
var news_scroll_items = document.getElementById("news_scroll_items");
var news_scroll_replaces = document.getElementById("news_scroll_replaces");
var speed = 70;//滚动速度
if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){
var rows = 100;//每行高度
}

var stim = 10; //停留时间倍数 * speed
var stop = 10; //初始化值,不管

news_scroll_replaces.innerHTML=news_scroll_items.innerHTML
function Marquees(){

if(news_scroll_replaces.offsetTop-news_scroll_bar.scrollTop <=0)
news_scroll_bar.scrollTop-=news_scroll_items.offsetHeight
else{
news_scroll_bar.scrollTop++
}
}
var MyMars=setInterval(Marquees,speed)
news_scroll_bar.onmouseover=function() {clearInterval(MyMars)}
news_scroll_bar.onmouseout=function() {MyMars=setInterval(Marquees,speed)}
</script>


目前这段代码,走一走就停了. 而且速度有点慢. 求高人帮忙解决下.
...全文
2421 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
街头小贩 2009-04-14
  • 打赏
  • 举报
回复
如果效果类4:http://u.discuz.net/home/
右中哪个《看看大家现在正在做什么…》效果,我把他哪个js 类扣出来了在这:http://www.t6new.cn/include/js/scrollclass.js
调用方式:

<ul id="scrollbody">
<%Call topHumanIndex()%>
</ul><script type="text/javascript">startMarquee(95, 60, 0, 'scrollbody');</script>


topHumanIndex过程打印的是<li>...<li>
chenxhcc 2009-04-14
  • 打赏
  • 举报
回复
详细效果见.wwww.web-pifa.com 站内快讯.

似乎不循环的样子. 刷新一下网站走一走,不刷新走一会就停了
yuqiangyuqiang 2009-04-14
  • 打赏
  • 举报
回复
function Marquee()
{
this.ID = document.getElementById(arguments[0]);
if(!this.ID)
{
alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
this.ID = -1;
return;
}
this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
this.Step = 1;
this.Timer = 30;
this.DirectionArray = {"top":0 , "up":0 , "bottom":1 , "down":1 , "left":2 , "right":3};
if(typeof arguments[1] == "number" || typeof arguments[1] == "string")this.Direction = arguments[1];
if(typeof arguments[2] == "number")this.Step = arguments[2];
if(typeof arguments[3] == "number")this.Width = arguments[3];
if(typeof arguments[4] == "number")this.Height = arguments[4];
if(typeof arguments[5] == "number")this.Timer = arguments[5];
if(typeof arguments[6] == "number")this.DelayTime = arguments[6];
if(typeof arguments[7] == "number")this.WaitTime = arguments[7];
if(typeof arguments[8] == "number")this.ScrollStep = arguments[8];
this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
this.ID.noWrap = true;
this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
if(arguments.length >= 7)this.Start();
}

Marquee.prototype.Start = function()
{
if(this.ID == -1)return;
if(this.WaitTime < 800)this.WaitTime = 800;
if(this.Timer < 20)this.Timer = 20;
if(this.Width == 0)this.Width = parseInt(this.ID.style.width);
if(this.Height == 0)this.Height = parseInt(this.ID.style.height);
if(typeof this.Direction == "string")this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];
this.HalfWidth = Math.round(this.Width / 2);
this.HalfHeight = Math.round(this.Height / 2);
this.BakStep = this.Step;
this.ID.style.width = this.Width + "px";
this.ID.style.height = this.Height + "px";
if(typeof this.ScrollStep != "number")this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;
var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td></tr></table>";
var templateTop = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;'><tr><td>MSCLASS_TEMP_HTML</td></tr><tr><td>MSCLASS_TEMP_HTML</td></tr></table>";
var msobj = this;
msobj.tempHTML = msobj.ID.innerHTML;
if(msobj.Direction <= 1)
{
msobj.ID.innerHTML = templateTop.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);
}
else
{
if(msobj.ScrollStep == 0 && msobj.DelayTime == 0)
{
msobj.ID.innerHTML += msobj.ID.innerHTML;
}
else
{
msobj.ID.innerHTML = templateLeft.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);
}
}
var timer = this.Timer;
var delaytime = this.DelayTime;
var waittime = this.WaitTime;
msobj.StartID = function(){msobj.Scroll()}
msobj.Continue = function()
{
if(msobj.MouseOver == 1)
{
setTimeout(msobj.Continue,delaytime);
}
else
{ clearInterval(msobj.TimerID);
msobj.CTL = msobj.Stop = 0;
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}

msobj.Pause = function()
{
msobj.Stop = 1;
clearInterval(msobj.TimerID);
setTimeout(msobj.Continue,delaytime);
}

msobj.Begin = function()
{
msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth / 2 : msobj.ID.scrollHeight / 2;
if((msobj.Direction <= 1 && msobj.ClientScroll <= msobj.Height + msobj.Step) || (msobj.Direction > 1 && msobj.ClientScroll <= msobj.Width + msobj.Step)) {
msobj.ID.innerHTML = msobj.tempHTML;
delete(msobj.tempHTML);
return;
}
delete(msobj.tempHTML);
msobj.TimerID = setInterval(msobj.StartID,timer);
if(msobj.ScrollStep < 0)return;
msobj.ID.onmousemove = function(event)
{
if(msobj.ScrollStep == 0 && msobj.Direction > 1)
{
var event = event || window.event;
if(window.event)
{
if(msobj.IsNotOpera)
{
msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
}
else
{
msobj.ScrollStep = null;
return;
}
}
else
{
msobj.EventLeft = event.layerX - msobj.ID.scrollLeft;
}
msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
}
}
msobj.ID.onmouseover = function()
{
if(msobj.ScrollStep == 0)return;
msobj.MouseOver = 1;
clearInterval(msobj.TimerID);
}
msobj.ID.onmouseout = function()
{
if(msobj.ScrollStep == 0)
{
if(msobj.Step == 0)msobj.Step = 1;
return;
}
msobj.MouseOver = 0;
if(msobj.Stop == 0)
{
clearInterval(msobj.TimerID);
msobj.TimerID = setInterval(msobj.StartID,timer);
}
}
}
setTimeout(msobj.Begin,waittime);
}

Marquee.prototype.Scroll = function()
{
switch(this.Direction)
{
case 0:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop >= this.ClientScroll)
{
this.ID.scrollTop -= this.ClientScroll;
}
this.ID.scrollTop += this.Step;
}
break;

case 1:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollTop <= 0)
{
this.ID.scrollTop += this.ClientScroll;
}
this.ID.scrollTop -= this.Step;
}
break;

case 2:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft >= this.ClientScroll)
{
this.ID.scrollLeft -= this.ClientScroll;
}
this.ID.scrollLeft += this.Step;
}
break;

case 3:
this.CTL += this.Step;
if(this.CTL >= this.ScrollStep && this.DelayTime > 0)
{
this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
this.Pause();
return;
}
else
{
if(this.ID.scrollLeft <= 0)
{
this.ID.scrollLeft += this.ClientScroll;
}
this.ID.scrollLeft -= this.Step;
}
break;
}
}
这个就是现在用的比较多的滚动js,可要调制速度等等

87,917

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧