移动轮播

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        *{
            margin:0;
            padding:0;
        }
       .all{
           height:100px;
           width:100px;
           border:1px solid #000;
           position:relative;
           margin:100px auto 0 auto;
           overflow: hidden;
       }
       .move{
           position:relative;
           width:500px;
           height:100px;

       }
        .move>div{
            height:100px;
            width:100px;
            color:white;
            font-size:40px;
            text-align:center;
            line-height:100px;
            float:left;
        }
        .one{
            background:red;
        }
        .two{
            background:greenyellow;
        }
        .three{
            background:blue;
        }
        .four{
            background:purple;
        }
        .five{
            background:yellow;
        }
        input{
            height:20px;
            width:40px;
        }
        .xxx{
            width:100px;
            margin:0 auto;
        }
        #right{
            margin-left:10px;
        }
    </style>
</head>
<body>
    <div class="all" id="all">
        <div class="move" id="move">
            <div class="one">1</div>
            <div class="two">2</div>
            <div class="three">3</div>
            <div class="four">4</div>
            <div class="five">5</div>
        </div>
    </div>
    <div class="xxx">
        <input type="button" value="prev" id="left">
        <input type="button" value="next" id="right" style="left:50px;">
    </div>
<script>
    window.onload=function(){
        var oLeft=document.getElementById("left");
        var oRight=document.getElementById("right");
        var oMove=document.getElementById("move");
        var aDiv=oMove.getElementsByTagName("div");
        var iSpeed=1;

        oRight.onclick=function(){
            var timer=setInterval(function(){
                oMove.style.left=oMove.offsetLeft-iSpeed+"px";
                iSpeed++;
                if(oMove.offsetLeft<-100){
                    oMove.offsetLeft=0;
                    clearInterval(timer);
                    oMove.style.left=0+"px";
                    var rua=oMove.removeChild(aDiv[0]);
                    oMove.appendChild(rua);
                }
            },100);
        }
       oLeft.onclick=function(){
           oMove.style.left=-100+"px";
           var rua=oMove.removeChild(aDiv[aDiv.length-1]);
           oMove.insertBefore(rua,aDiv[0]);
           var timer=setInterval(function(){
               oMove.style.left=oMove.offsetLeft+iSpeed+"px";
               iSpeed++;
                if(oMove.offsetLeft>0){
                    oMove.style.left=0;
                    clearInterval(timer);
                }

           },100)
       }





    }
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值