继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

JavaScript动画之无缝流水框

Leal_Gullden
关注TA
已关注
手记 15
粉丝 23
获赞 267

效果图
图片描述

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>temp</title>
    <link rel="stylesheet" type="text/css" href="../css/demo4.css">
    <script src="../js/demo4.js"></script>
</head>
<body>
    <div id="box">
        <ul id="con1">
            <li>****************1****************</li>
            <li>****************2****************</li>
            <li>****************3****************</li>
            <li>****************4****************</li>
            <li>****************5****************</li>
            <li>****************6****************</li>
            <li>****************7****************</li>
            <li>****************8****************</li>
            <li>****************9****************</li>
        </ul>
    </div>
</body>
</html>
*{
    margin: 0;
    padding: 0;
}
#box{
    width: 350px;
    height: 25px;
    margin: 50px auto;
    border: 4px solid #ccc;
    text-align: center;
    overflow: hidden;
}
#box ul{
    list-style: none;
}
#box ul li{
    height: 25px;
    line-height: 25px;
}
window.onload=function(){
    var timer = null;
    var dtimer = null;
    var speed = 50;
    var dtime = 2000;
    var dheight = 25;
    var box = document.getElementById('box');
    box.scrollTop=0;
    box.innerHTML += box.innerHTML;
    dtimer = setTimeout(startScroll,dtime);

    function startScroll(){
        timer = setInterval(function(){
            box.scrollTop++;
            if(box.scrollTop===box.scrollHeight/2){
                box.scrollTop = 0;
            }
            if(box.scrollTop % dheight ===0){
                clearInterval(timer);
                clearTimeout(dtimer);
                dtimer = setTimeout(startScroll,dtime);
            }
        },speed);
    }
};
打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP