js 上下文字滚动效果

  1. 云栖社区>
  2. 博客>
  3. 正文

js 上下文字滚动效果

keller.zhou 2016-10-25 10:36:46 浏览468
展开阅读全文
<!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>文字列表无缝向上滚动JavaScript代码</title>
    <style>
        *{margin:0px;padding:0px;border:0px;}
        body{font-size:12px}
        #demo1{
            height:auto;
            text-align:left;
        }
        #demo2{
            height:auto;
            text-align:left;
        }
        #demo1  li{
            list-style-type:none;
            height:22px;
            background:url() no-repeat left center;
            text-align:left;
            text-indent:15px;
        }
        #demo2  li{
            list-style-type:none;
            height:22px;
            background:url() no-repeat left center;
            text-align:left;
            text-indent:15px;
        }
    </style>
</head>
<body>

<div>

    <div id="demo" style="overflow:hidden;height:80px;width:100%;">
        <ul id="demo1">
            <li><a href="/soft/4085.shtml" target="_blank">XP Menu 仿QQ菜单管理器左侧菜单</a></li><li><a href="/soft/5884.shtml" target="_blank">多层嵌套的一个层展开</a></li><li><a href="/soft/1852.shtml" target="_blank">《Java2核心技术卷2:高级特性》第7版</a></li><li><a href="/soft/1286.shtml" target="_blank">CSS、HTML教程打包下载 (CHM)</a></li><li><a href="/soft/4216.shtml" target="_blank">《C++ Primer》中文第四版 chm</a></li><li><a href="/soft/3388.shtml" target="_blank">C++工资管理系统(Access)</a></li><li><a href="/soft/2009.shtml" target="_blank">非常牛的左侧栏JS折叠菜单</a></li>
        </ul>
        <ul id="demo2"></ul>
    </div>

</div>

<script>
    var speed=40
    var demo=document.getElementById("demo");
    var demo2=document.getElementById("demo2");
    var demo1=document.getElementById("demo1");
    demo2.innerHTML=demo1.innerHTML
    function Marquee(){

        if(demo2.offsetTop-demo.scrollTop<=demo.offsetTop)
            demo.scrollTop-=demo1.offsetHeight
        else{
            demo.scrollTop++
        }
    }
    var MyMar=setInterval(Marquee,speed)
    demo.onmouseover=function() {clearInterval(MyMar)}
    demo.onmouseout=function() {MyMar=setInterval(Marquee,speed)}
</script>
</body>
</html>

网友评论

登录后评论
0/500
评论
keller.zhou
+ 关注