vue实现轮播图

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
         /* 去除默认样式 */
        *{margin: 0;padding: 0;}
        .clearfix:after,
        .clearfix:before{content: '';display: table;}
        .clearfix:after{clear: both;}
        input{ border: none; outline: none; background-color: transparent; }
        ul,ol{list-style-type: none;}
        a{text-decoration: none;}
        img{vertical-align: top;}
        em,i{font-style: normal;}

        #box{
            width: 1000px;
            height: 600px;
            position: relative;
            margin: 40px auto;
        }
        .list_box{
            width: 1000px;
            position: relative;
            height: 600px;
            overflow: hidden;
        }
        .list_box ul{
            position: absolute;
            top: 0;
            left: 0;
            display: flex;
        }
        .list_box ul li{
            width: 1000px;
            flex-shrink: 0;
            height: 600px;
        }
        .list_box ul li img{
            width: 100%;
            height: 100%;
        }
        .list_box div{
            position: absolute;
            bottom: 0 ;
            left: 0;
            width: 100%;
            text-align: center;
        }
        .list_box div span{
            display: inline-block;
            width: 10px;
            height: 10px;
            background-color: #fff;
            border-radius: 50%;
            margin: 5px 10px;
        }
        .list_box div .active{
            background-color: red;
        }
        .left,
        .right{
            display: inline-block;
            width: 50px;
            height: 50px;
            font-size: 40px;
            color: #fff;
            position: absolute;
            top: 50%;
            text-align: center;
        }
        .left{
            left: 0px;
        }
        .right{
            right: 0px;
        }
    </style>
</head>
<body>
    <div id="box">
        <div class="list_box">
            <ul :style='{left: this.index * -1000 + "px"}'>
                <li  v-for="(i, $index) in arr" :key="$index"><img :src='i' ></li>
            </ul>
            <div>
                <span v-for="(i, $index) in arr.length" :key="$index" :class="$index==index?'active':''" ></span>
            </div>
            <span class="left" @click='btna()'>&lt;</span>
            <span class="right" @click='btnb()'>&gt;</span>
        </div>
        <!-- {{index * 1000}} -->
        <!-- <div v-for="(i, $index) in arr" :key="$index"  >{{i}}</div> -->
    </div>
</body>
<script src="./vue.js"></script>
<script>
    new Vue({
        el:'#box',
        data:{
            arr:[
                './images/1.jpg',
                './images/2.jpg',
                './images/3.jpg',
                './images/4.jpg',
                './images/5.jpg',
                './images/6.jpg',
                './images/7.jpg',
                './images/8.jpg',
                './images/9.jpg',
                './images/10.jpg'
            ],
            index : 0
        },
        methods:{
            btna(){
                console.log(this.index)
                this.index--
                if(this.index < 0){
                    this.index = this.arr.length - 1
                }
            },
            btnb(){
                console.log(this.index)
                this.index++
                if(this.index > this.arr.length - 1){
                    this.index = 0
                }
            }
        }
    })
</script>
</html>
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值