当前位置:编程学习 > C#/ASP.NET >>

js 公告无间隔循环向上滚动

公告栏里的公告列表向上滚动,是无间隔循环向上滚动的,不知道JS是怎么写的,谁有完整的例子吗, 谢谢大家. --------------------编程问答-------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>

<div id="Div1" style="overflow: hidden; width: 128px; height: 100px;">
                            <div id="Div2">
                                a<br />a<br />a<br />a<br />a<br />a<br />a<br />
b
c
cd

                            </div>
                            <div id="Div3">
                            </div>
                        </div>

                        <script language="javascript">
                                 var speed=30
                                Div3.innerHTML=Div2.innerHTML

                                function Marquee(){
                                if(Div3.offsetTop-Div1.scrollTop<=0)
                                Div1.scrollTop-=Div2.offsetHeight
                                else{
                                Div1.scrollTop++
                                }
                                }
                                var MyMar=setInterval(Marquee,speed)
                                Div1.onmouseover=function() {clearInterval(MyMar)}
                                Div1.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
                        </script>

</body>
</html>



把上面的代码保存成一个网页,运行试试!~~~~无缝隙,自动循环!~~~ --------------------编程问答--------------------
<style>a{display:block;font-size:15px};</style>
<div id="div1" style="width:300px;height:68px;overflow:hidden">
<a href="javascript:">1,你可曾有过无数的梦想,</a>
<a href="javascript:">2,却在时光的流逝里幻灭 </a>
<a href="javascript:">3,你可曾对未来期待憧憬,</a>
<a href="javascript:">4,却在成长的岁月中迷失</a>
<a href="javascript:">5,CSDN中国程序员论坛</a>
<a href="javascript:">6,大家一起来</a>
<a href="javascript:">7,好象都很不错的样子</a>
</div> 
<script>
var t=setInterval(myfunc,1000)
var d=document.getElementById("div1")
function myfunc(){
var o=d.firstChild
d.removeChild(o)
d.appendChild(o)
}
d.onmouseover=function(){clearInterval(t)}
d.onmouseout=function(){t=setInterval(myfunc,1000)}
</script>


2,

<div id="marquees">
   <a href="#">链接一</a><br>
   <br>
   <a href="#">链接二</a><br>
   <br>
   <a href="#">链接三</a><br>
   <br>
   <a href="#">链接四</a><br>
   <br>
</div> 
<script language="JavaScript">

marqueesHeight=200;
stopscroll=false;

with(marquees){
   style.width=0;
   style.height=marqueesHeight;
   style.overflowX="visible";
   style.overflowY="hidden";
   noWrap=true;
   onmouseover=new Function("stopscroll=true");
   onmouseout=new Function("stopscroll=false");
}
document.write('<div id="templayer" style="position:absolute;z-index:1;visibility:hidden"></div>');

preTop=0; currentTop=0; 

function init(){
   templayer.innerHTML="";
   while(templayer.offsetHeight<marqueesHeight){
     templayer.innerHTML+=marquees.innerHTML;
   }
   marquees.innerHTML=templayer.innerHTML+templayer.innerHTML;
   setInterval("scrollUp()",10);
}
document.body.onload=init;

function scrollUp(){
   if(stopscroll==true) return;
   preTop=marquees.scrollTop;
   marquees.scrollTop+=1;
   if(preTop==marquees.scrollTop){
     marquees.scrollTop=templayer.offsetHeight-marqueesHeight;
     marquees.scrollTop+=1;
   }
}
</script>

--------------------编程问答-------------------- JavaScript 无缝上下左右滚动加定高定宽停顿效果  --------------------编程问答-------------------- 楼上的可以的 试试吧
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,