<style>
td{font-size:12px;}
</style>
<DIV align="center">
<table width=380 border=0 cellspacing=0 >
<tr>
<td>
<div id="icefable1" style="width:1500;">
<TABLE cellSpacing=0 cellPadding=0 width=380 border=0>
<TBODY>
<TR>
<TD height=18>·无忧脚本欢迎您</TD>
<TD height=18>·无忧脚本--编程爱好者的乐园</TD>
</TR>
<TR>
<TD height=18>·无忧脚本-紫色真情</TD>
<TD height=18>·欢迎来看俺的站-efenger.com</A></TD>
</TR>
<TR>
<TD height=18>·天桥商务</TD>
<TD height=18>·天桥科技</TD>
</TR>
<TR><TD height=18>·让天下的生意容易一点</TD>
<TD height=18>·天桥欢迎您</TD>
</TR>
<TR>
<TD height=18>·无忧脚本欢迎您</TD>
<TD height=18>·无忧脚本--编程爱好者的乐园</TD>
</TR>
</TBODY>
</TABLE>
</div>
<div id="icefable2" style="position:absolute;z-index:1;visibility:hidden">
</div>
</td>
</tr></table>
<script>
marqueesHeight=19;
stopscroll=false;
icefable1.scrollTop=0;with(icefable1){
style.width=0;
style.height=marqueesHeight;
style.overflowX="visible";
style.overflowY="hidden";
noWrap=true;
onmouseover=new Function("stopscroll=true");
onmouseout=new Function("stopscroll=false");
}preTop=0; currentTop=0; stoptime=0;
var intervar;
function init_srolltext(){
icefable2.innerHTML="";
icefable2.innerHTML+=icefable1.innerHTML; icefable1.innerHTML=icefable2.innerHTML+icefable2.innerHTML;
alert(icefable1.offsetHeight);
intervar=setInterval("scrollUp()",20);
}function scrollUp(){
if(stopscroll==true) return;
currentTop+=1;
//19*20后+50*20 后归0
if(currentTop==19)
{
stoptime+=1;
currentTop-=1;
if(stoptime==50)
{
currentTop=0;
stoptime=0;
}
}
else {
preTop=icefable1.scrollTop;
//每次滚动的条数
icefable1.scrollTop+=1;
//offsetHeight是自身元素的高度,scrollHeight是自身元素的高度+隐藏元素的高度
if(preTop==icefable1.scrollTop){
icefable1.scrollTop=icefable2.offsetHeight-marqueesHeight;
icefable1.scrollTop+=1;
}
}}
init_srolltext();
</script>
</DIV> <br>其中这一行:
if(preTop==icefable1.scrollTop){
这是什么原因这两个值会相等我十在是不明白,各们老师,给看看,能否详细说一下函数
scrollUp()
谢谢了.
td{font-size:12px;}
</style>
<DIV align="center">
<table width=380 border=0 cellspacing=0 >
<tr>
<td>
<div id="icefable1" style="width:1500;">
<TABLE cellSpacing=0 cellPadding=0 width=380 border=0>
<TBODY>
<TR>
<TD height=18>·无忧脚本欢迎您</TD>
<TD height=18>·无忧脚本--编程爱好者的乐园</TD>
</TR>
<TR>
<TD height=18>·无忧脚本-紫色真情</TD>
<TD height=18>·欢迎来看俺的站-efenger.com</A></TD>
</TR>
<TR>
<TD height=18>·天桥商务</TD>
<TD height=18>·天桥科技</TD>
</TR>
<TR><TD height=18>·让天下的生意容易一点</TD>
<TD height=18>·天桥欢迎您</TD>
</TR>
<TR>
<TD height=18>·无忧脚本欢迎您</TD>
<TD height=18>·无忧脚本--编程爱好者的乐园</TD>
</TR>
</TBODY>
</TABLE>
</div>
<div id="icefable2" style="position:absolute;z-index:1;visibility:hidden">
</div>
</td>
</tr></table>
<script>
marqueesHeight=19;
stopscroll=false;
icefable1.scrollTop=0;with(icefable1){
style.width=0;
style.height=marqueesHeight;
style.overflowX="visible";
style.overflowY="hidden";
noWrap=true;
onmouseover=new Function("stopscroll=true");
onmouseout=new Function("stopscroll=false");
}preTop=0; currentTop=0; stoptime=0;
var intervar;
function init_srolltext(){
icefable2.innerHTML="";
icefable2.innerHTML+=icefable1.innerHTML; icefable1.innerHTML=icefable2.innerHTML+icefable2.innerHTML;
alert(icefable1.offsetHeight);
intervar=setInterval("scrollUp()",20);
}function scrollUp(){
if(stopscroll==true) return;
currentTop+=1;
//19*20后+50*20 后归0
if(currentTop==19)
{
stoptime+=1;
currentTop-=1;
if(stoptime==50)
{
currentTop=0;
stoptime=0;
}
}
else {
preTop=icefable1.scrollTop;
//每次滚动的条数
icefable1.scrollTop+=1;
//offsetHeight是自身元素的高度,scrollHeight是自身元素的高度+隐藏元素的高度
if(preTop==icefable1.scrollTop){
icefable1.scrollTop=icefable2.offsetHeight-marqueesHeight;
icefable1.scrollTop+=1;
}
}}
init_srolltext();
</script>
</DIV> <br>其中这一行:
if(preTop==icefable1.scrollTop){
这是什么原因这两个值会相等我十在是不明白,各们老师,给看看,能否详细说一下函数
scrollUp()
谢谢了.
定位鼠标位置的吧
代码如下:
<div id="marquees"> <!-- 这些是字幕的内容,你可以任意定义 --> <a href="你的连接地址">链接1</a>
<br> <a href="你的连接地址">链接2</a>
<br> <a href="你的连接地址">链接3</a>
<br> <a href="你的连接地址">链接4</a>
<br> <!-- 字幕内容结束 -->
</div>
<!-- 以下是javascript代码 -->
<script language="javascript">
<!--
marqueesHeight=200; //内容区高度
stopscroll=false; //这个变量控制是否停止滚动
with(marquees){
noWrap=true; //这句表内容区不自动换行
style.width=0; //于是我们可以将它的宽度设为0,因为它会被撑大
style.height=marqueesHeight;
style.overflowY="hidden"; //滚动条不可见
onmouseover=new Function("stopscroll=true"); //鼠标经过,停止滚动
onmouseout=new Function("stopscroll=false"); //鼠标离开,开始滚动
}
//这时候,内容区的高度是无法读取了。下面输出一个不可见的层"templayer",稍后将内容复制到里面:
document.write('<div id="templayer" style="position:absolute;z-index:1;visibility:hidden"></div>');
function init(){ //初始化滚动内容
//多次复制原内容到"templayer",直到"templayer"的高度大于内容区高度:
while(templayer.offsetHeight<marqueesHeight){
templayer.innerHTML+=marquees.innerHTML;
} //把"templayer"的内容的“两倍”复制回原内容区:
marquees.innerHTML=templayer.innerHTML+templayer.innerHTML;
//设置连续超时,调用"scrollUp()"函数驱动滚动条:
setInterval("scrollUp()",20);
}
document.body.onload=init;
preTop=0; //这个变量用于判断滚动条是否已经到了尽头
function scrollUp(){ //滚动条的驱动函数
if(stopscroll==true) return; //如果变量"stopscroll"为真,则停止滚动
preTop=marquees.scrollTop; //记录滚动前的滚动条位置
marquees.scrollTop+=1; //滚动条向下移动一个像素
//如果滚动条不动了,则向上滚动到和当前画面一样的位置
//当然不仅如此,同样还要向下滚动一个像素(+1):
if(preTop==marquees.scrollTop){
marquees.scrollTop=templayer.offsetHeight-marqueesHeight+1;
}
}
-->
</script>
icefable1.scrollTop=icefable2.offsetHeight-marqueesHeight;
这是一个替换的过程,就好象冒泡排序中一样,icefable2中的一部分补充到1里
举例吧,一个队列转圈,marquees就好像8个人在在16个人的距离中转一样
LZ的例子就是把这空出来的8个人用存在的那8个来复制后补充上,这样就是16个在首尾连接的转动了~
<br> <a href="你的连接地址">链接2</a>
<br> <a href="你的连接地址">链接3</a>
<br> <a href="你的连接地址">链接4</a>
<br> <!-- 字幕内容结束 -->
</div>
<!-- 以下是javascript代码 -->
<script language="javascript">
<!--
marqueesHeight=200; //内容区高度
stopscroll=false; //这个变量控制是否停止滚动
with(marquees){
noWrap=true; //这句表内容区不自动换行
style.width=0; //于是我们可以将它的宽度设为0,因为它会被撑大
style.height=marqueesHeight;
style.overflowY="hidden"; //滚动条不可见
onmouseover=new Function("stopscroll=true"); //鼠标经过,停止滚动
onmouseout=new Function("stopscroll=false"); //鼠标离开,开始滚动
}
//这时候,内容区的高度是无法读取了。下面输出一个不可见的层"templayer",稍后将内容复制到里面:
document.write('<div id="templayer" style="position:absolute;z-index:1;visibility:hidden"></div>');
function init(){ //初始化滚动内容
//多次复制原内容到"templayer",直到"templayer"的高度大于内容区高度:
while(templayer.offsetHeight<marqueesHeight){
templayer.innerHTML+=marquees.innerHTML;
} //把"templayer"的内容的“两倍”复制回原内容区:
marquees.innerHTML=templayer.innerHTML+templayer.innerHTML;
//设置连续超时,调用"scrollUp()"函数驱动滚动条:
setInterval("scrollUp()",20);
}
document.body.onload=init;
preTop=0; //这个变量用于判断滚动条是否已经到了尽头
function scrollUp(){ //滚动条的驱动函数
if(stopscroll==true) return; //如果变量"stopscroll"为真,则停止滚动
preTop=marquees.scrollTop; //记录滚动前的滚动条位置
marquees.scrollTop+=1; //滚动条向下移动一个像素
//如果滚动条不动了,则向上滚动到和当前画面一样的位置
//当然不仅如此,同样还要向下滚动一个像素(+1):
if(preTop==marquees.scrollTop){
marquees.scrollTop=templayer.offsetHeight-marqueesHeight+1;
}
}
-->
</script>