JQ轮播图

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        *{
            margin:0;
            padding:0;
            text-decoration: none;
        }
        body{
            padding:20px;
        }

        #list{
            width: 3000px;
            height:333px;
            z-index: 1;
            position: absolute;
            animation: myfirst 10s infinite;
        }
        #list img{
            float: left;
        }
       /* @keyframes myfirst {
            0%{transform:translateX(0px)}
            25%{transform:translateX(-500px)}
            50%{transform:translateX(-1000px)}
            75%{transform:translateX(-1500px)}
            100%{transform:translateX(-2000px)}

        }*/
        #container{
            margin:0 auto;
            width:500px;
            height:333px;
            border: 3px solid #333333;
            overflow: hidden;
            position: relative;

        }


        #buttons{
            position: absolute;
            height: 10px;
            width: 100px;
            z-index: 2;
            bottom:20px;
            left:250px;
            border-radius: 50%;
            background: #333;
            margin-left:5px ;
        }
        #buttons span{
            cursor: pointer;
            float: left;
            border:1px solid #fff;
            width:10px;
            height: 10px;
            border-radius: 50%;
            background-color: #333333;
            margin-right:5px;
        }
        #buttons .on{
            background:orangered;
        }
        .arrow{
            cursor: pointer;display: none;line-height: 39px;
            text-align:center;
            font-size: 36px;
            font-weight:bold;
            width: 40px;
            height:40px;
            position: absolute;
            z-index:2;
            top:180px;
            background-color: rgba(0,0,0,.3);color: #ffffff;
        }
        .arrow:hover{
            background-color: rgba(0,0,0,.7);}
        #container:hover .arrow{
            display: block;

        }
        #prev{left:20px;}
        #next{
            right: 30px;}
    </style>
    <script src="jquery-2.0.0.min.js">

    </script>
    <script type="text/javascript">
        $(function(){
            var container = $("#container")
            var list = $("#list")
            var prev= $("#next")
            var next= $("#prev")
            var buttons = $("#buttons span")
            console.log(prev)
            var index = 1
            function showbutton(){
                buttons.eq(index-1).addClass('on').siblings().removeClass("on")
            }
            function animate(offset){
                var newleft = parseInt(list.css("left"))+offset;
                console.log(newleft);
                list.css({'left':newleft})
                if(newleft>0){
                    //newleft = -2400
                    // list.css({'left':newleft})
                    list.css({'left':-2000+"px"})
                }
                if(newleft<-2000){
                    // newleft =0
                    list.css({'left':0+"px"})
            }
            }
           // next.onclick(function({})
         /*   next.bind('click',function(){
               // console.log("11111")
                var newleft = parseInt(list.css("left")) - 600;
                console.log(newleft);
                list.css({'left':newleft})
                if(newleft>0){
                    //newleft = -2400
                   // list.css({'left':newleft})
                    list.css({'left':-2400+"px"})
                }
                if(newleft<-2400){
                   // newleft =0
                    list.css({'left':0+"px"})
                }
            })*/
            next.bind('click',function(){
                // console.log("11111")

               index +=1;
                showbutton();
                animate(-500)
            })
            prev.bind('click',function(){
                // console.log("11111")

                index -=1;
                showbutton();
                animate(+500)
            })
        })
    </script>
</head>
<body>
    <div id="container">

        <div id="list" style="">
            <img src="1.jpg" alt="1">
            <img src="2.jpg" alt="2">
            <img src="3.jpg" alt="3">
            <img src="4.jpg" alt="4">
            <img src="5.jpg" alt="5">
        </div>
        <div id="buttons">
            <span index="1" class="on"></span>
            <span index="2" ></span>
            <span index="3" ></span>
            <span index="4" ></span>
            <span index="5" ></span>

    </div>
        <a href="javascript:;" id="prev" class="arrow">&lt;</a>
        <a href="javascript:;" id="next" class="arrow">&gt;</a>
        </div>
</body>
</html>

//溢出隐藏
//定位//所有图片平铺的宽度//定位问题 利用偏移量进行切换//浮动(不用清除浮动) //层级,使按钮置于顶层//和第一张图片位置比较//归位到第五张图片//和最后一张图片位置比较//归位到第一张图片

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值