天天看点

用原生JS实现maquee上下滚动公告效果

?ㄥ????JS瀹???aquee

<!DOCTYPE HTML>
<html>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>

<head>
    <style type="text/css">
        ul{
            /*涓?瑕?margin????婊???浼???缂???*/
            margin:0;
        }
        div {
            /*overflow hidden路??????娉???浣?涓??㈢????瀹?/
            overflow: hidden;
            width: 75px;
            height: 100px;
            margin-left: 29%;
            margin-top: 10%;
            background: aqua;
            border-top: 1px solid red;
            border-bottom: 1px solid red;
        }
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>??缂?婊???lt;/title>
</head>
<body>
<div id="ca">
    <ul id="c1">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
        <li>7</li>
        <li>8</li>

    </ul>
    <ul id="c2"></ul>
</div>
</body>
<script language="javascript" type="text/javascript">
    var c1=document.getElementById("c1");
    var c2=document.getElementById("c2");
    var ca=document.getElementById("ca");
    /*灏?绗?涓?涓?ul???艰??肩?绗?浜?涓?  褰?绗?涓?涓?澶撮?ㄦ?澶辨???辩??浜?涓??ユ?剧ず*/
    c2.innerHTML=c1.innerHTML;
    var cas=null;
    window.onload=function(){
        st();
    }
    cas=setInterval('st()',50);
    function st(){
        //clearInterval(cas);
        /*濡???婊??ㄩ?垮害澶т?绗?涓?涓?ul??楂?搴? 灏遍??瑕?灏?绗?涓?涓?ul???板??澶? */
        if(ca.scrollTop>=c1.offsetHeight){
            ca.scrollTop=0;
        }else{
            ca.scrollTop++;
        }/*榧???绉诲?ュ氨娓??ゆ??ゅ???跺??/
        ca.onmouseover=function() {
            clearInterval(cas);
        }
        ca.onmouseout=function() {
            cas=setInterval('st()',50);
        }

    }
</script>
</html>
                

继续阅读