主题:  请教文字自上而下循环滚动,如央视首页上节目表,不留空白

firedot

职务:普通成员
等级:1
金币:0.0
发贴:47
注册:2001/11/16 15:01:29
#12002/5/9 11:08:00
http:www.cctv.com.cn
做央视节目表这种没有空白文字上下重复循环滚动的效果
源代码当下来看了,可惜水平有限,不知道哪一段是主要的,烦请各位帮忙,谢了!



=ridincal=

职务:管理员
等级:7
金币:20.0
发贴:5886
注册:2004/1/13 11:47:04
#22002/5/9 11:14:29
源代码呢?



firedot

职务:普通成员
等级:1
金币:0.0
发贴:47
注册:2001/11/16 15:01:29
#32002/5/9 16:05:31
太长了,不方便贴上来,烦请大侠们高抬贵鼠,到央视首页看看便知



=ridincal=

职务:管理员
等级:7
金币:20.0
发贴:5886
注册:2004/1/13 11:47:04
#42002/5/9 16:46:26
做了个最简页面:


页面:点这儿参观



=ridincal=

职务:管理员
等级:7
金币:20.0
发贴:5886
注册:2004/1/13 11:47:04
#52002/5/9 16:46:53
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT language=javascript>
<!--CodeModifiedByRidincal-->
isns = navigator.appName == "Netscape";

function tvchannel_str(channel_id,channel_name)
{
	this.channel_id=channel_id
	this.channel_name=channel_name
}

tvchannel=new Array()

tvchannel[ 1]=new tvchannel_str('1','栏目1');

tvchannel[ 2]=new tvchannel_str('2','栏目2');

tvchannel[ 3]=new tvchannel_str('3','栏目3');

tvchannel[ 4]=new tvchannel_str('4','栏目4');

tvchannel[ 5]=new tvchannel_str('5','栏目5');


function tvitem_str(channel_id,tv_content,tv_url)
{
	this.channel_id=channel_id
	this.tv_content=tv_content
	this.tv_url=tv_url
}

tvitem=new Array()

tvitem[ 1]=new tvitem_str('1','&nbsp;&nbsp;消息1','')

tvitem[ 2]=new tvitem_str('1','&nbsp;&nbsp;消息2','')

tvitem[ 3]=new tvitem_str('2','&nbsp;&nbsp;消息1','')

tvitem[ 4]=new tvitem_str('2','&nbsp;&nbsp;消息2','')

tvitem[ 5]=new tvitem_str('3','&nbsp;&nbsp;消息1','')

tvitem[ 6]=new tvitem_str('3','&nbsp;&nbsp;消息2','')

tvitem[ 7]=new tvitem_str('4','&nbsp;&nbsp;消息1','')

tvitem[ 8]=new tvitem_str('4','&nbsp;&nbsp;消息2','')

tvitem[ 9]=new tvitem_str('5','&nbsp;&nbsp;消息1','')

tvitem[ 10]=new tvitem_str('5','&nbsp;&nbsp;消息2','')



channelCount=0
var moveSpeed=100
function tvDivWrt()
{
	
	tempmem=new Array()
	for(i=1;i<=tvchannel.length-1;i++)
	{
		tempmem[i]=new Array()
		findchannel=false
		channelnum=tvchannel[i].channel_id
		k=0
		for(j=1;j<=tvitem.length-1;j++)
		{
			if(tvitem[j].channel_id==channelnum)
			{
				findchannel=true
				k++
				tempmem[i][k]=j
			}
		}
		if(findchannel)
		{
			channelCount++
if(!isns) document.write("<div id=text"+channelCount+">"+tvchannel[i].channel_name+"
")
else document.write("<layer id=text"+channelCount+">"+tables+tvchannel[i].channel_name+"
")

			for(ii=1;ii<=tempmem[i].length-1;ii++)
			{
				jj=tempmem[i][ii]
				if(tvitem[jj].tv_url=='') document.write(tvitem[jj].tv_content+"
")
				else document.write("<a href="+tvitem[jj].tv_url+" target=_blank class=a5>"+tvitem[jj].tv_content+"</a>
")
			}
if(!isns) document.write("
</div>")
else document.write("
"+tablee+"</layer>")
			
		}
	}
				
			
}

if(isns)
{
	tag0='document.divnews.document.clipnews.document.'
	tag1='document.divnews.document.clipnews.'
	tag2=''
}
else
{
	tag0=''
	tag1=''
	tag2='.style'
}

divname='text'
heightLimit=226
tables='<table cellspacing=0 cellpadding=0 border=0 width=300><tr><td>'
tablee='</td></tr></table>'

function init()
{
	if(!isns)
	{	
postop=0
	for(i=1;i<=channelCount;i++)
	{
		eval(divname+i+'.style.top='+postop)
		eval(divname+i+'.style.position="absolute"')
		divheight=eval(divname+i+'.offsetHeight')
		postop+=divheight
	}
	alltop=eval(divname+channelCount+'.style.pixelTop')
	allheight=eval(divname+channelCount+'.offsetHeight')
	allpos=alltop+allheight
	if(allpos>heightLimit) newsmove()
}
	else {newsmove();eval(tag1+'visibility="show"')}
}

steph=2
mm=false
function newsmove()
{
	mm=true
	xmin=1
	for(i=1;i<=channelCount;i++)
	{
		if(isns) xtop=eval(tag0+divname+xmin+'.top')
		else xtop=eval(divname+xmin+'.style.pixelTop')
		if(isns) nitop=eval(tag0+divname+i+'.top')
		else nitop=eval(divname+i+'.style.pixelTop')
		if(nitop<xtop) xmin=i
	}
	if(isns) tt=eval(tag0+divname+xmin+'.top');
	else tt=eval(divname+xmin+'.style.pixelTop');
	tt-=steph;
	eval(tag0+divname+xmin+tag2+'.top=tt');
	xmax=xmin-1
	if(xmin==1) xmax=channelCount
	if(xmin>=1&&xmin<channelCount)
	for(i=xmin+1;i<=channelCount;i++)
	{
		j=i-1
		follow(i,j)		
	}
	if(xmin!=1)
	for(i=1;i<=xmax;i++)
	{
		j=i-1
		if(j==0) j=channelCount
		follow(i,j)
	}
	for(i=1;i<=channelCount;i++)
	{
		if(isns) topi=eval(tag0+divname+i+'.top')
		else topi=eval(divname+i+'.style.pixelTop')
		if(isns) heighti=eval(tag0+divname+i+'.clip.height')
		else heighti=eval(divname+i+'.offsetHeight')
		bottomi=topi+heighti
		if(bottomi<0)
		eval(tag0+divname+i+tag2+'.top=heightLimit')
	}

	if(mm) domove=setTimeout('newsmove()',moveSpeed);
}

function stopm()
{
	if(mm)
	{clearTimeout(domove)
	mm=false}
}

function startm()
{
	if(!mm) newsmove()
}

function follow(nexti,prei)
{
	if(isns) newtop=eval(tag0+divname+prei+'.top')
	else newtop=eval(divname+prei+'.style.pixelTop')
	if(isns) newheight=eval(tag0+divname+prei+'.clip.height')
	else newheight=eval(divname+prei+'.offsetHeight')
	newpos=newtop+newheight
	if(newpos>heightLimit) newpos=heightLimit
	eval(tag0+divname+nexti+tag2+'.top='+newpos)
}

</SCRIPT>
</head>

<body bgcolor="#FFFFFF" text="#000000" onload=init()>
<TABLE>
<TR>
<TD vAlign=top height=234><!-- 文字滚动:for ie --><NOLAYER>
                  <DIV id=divnews onmouseover=stopm() 
                  style="LEFT: 8px; VISIBILITY: visible; WIDTH: 310px; POSITION: relative; TOP: 0px; HEIGHT: 226px" 
                  onmouseout=startm()>
                  <DIV id=clipnews 
                  style="LEFT: 0px; WIDTH: 310px; CLIP: rect(0px 310px 221px 0px); POSITION: absolute; TOP: 4px; HEIGHT: 226px">
                  <SCRIPT>tvDivWrt()</SCRIPT>
                  </DIV></DIV></NOLAYER><ILAYER id=layer1 height="50" 
                  width="300" visibility="hidden"></ILAYER></TD>
				  </TR></TABLE>
</body>
</html>


编辑历史:[此帖最近一次被 ridincal 编辑过(编辑时间:2004-04-22 21:10:33)]


=ridincal=

职务:管理员
等级:7
金币:20.0
发贴:5886
注册:2004/1/13 11:47:04
#62002/5/9 16:48:39
将script onload 和 DIV 考入你的页面,另外注意修改tvchannel(栏目)和tvitem(消息)