使用vue+transition实现简单的轮播图效果
2019-07-24 10:05
495 查看
效果图
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <style> #app { width: 500px; height: 200px; margin: 0 auto; position: relative; overflow: hidden; } ul li { list-style: none; } .item_body { width: 1500px; padding: 0; /* display: flex; */ transition: transform .4s; } .item { width: 500px; height: 200px; float: left; text-align: center; line-height: 200px; } .btns { z-index: 1; position: absolute; left: 50%; bottom: 0px; margin-left: -45px; padding: 0; } .btn { width: 10px; height: 10px; background-color: gray; border-radius: 50%; float: left; margin: 10px; } .active { background-color: blue; } .right, .left { position: absolute; width: 20px; height: 40px; line-height: 40px; text-align: center; background-color: #eee55e; color: gray; top: 50%; margin-top: -20px; cursor: pointer; } .left { left: 5px; } .right { right: 5px; } </style> </head> <body> <div id="app"> <ul class="item_body" :style="{transform:'translate('+-mark*500+'px,0)'}" v-on:mouseover="stop()" v-on:mouseout="play()"> <li class="item" v-for="(item,index) in items" :key="index" :style="{background:item.backgroundColor}"> {{item.backgroundColor}} </li> </ul> <ul class="btns"> <li :class="['btn',{'active':index===mark}]" v-for="(item,index) in items" :key="index" @click='move(index)'> </li> </ul> <div class="right" v-on:click='moveR'>></div> <div class="left" @click="moveL"><</div> </div> <script src="../js/vue.js"></script> <script> const app = new Vue({ el: "#app", data: { timer: null, mark: 0, items: [ { backgroundColor: 'red', }, { backgroundColor: 'green', }, { backgroundColor: 'orangered', } ], }, methods: { autoplay() { this.mark++; if (this.mark > 2) { this.mark = 0; } }, play() { this.timer = setInterval(this.autoplay, 3000) }, stop() { clearInterval(this.timer) }, // 点击小圆点 move(index) { console.log(index); console.log(this); this.mark = index }, // 右点 moveR() { // console.log(this.index); this.mark++; console.log(this.mark); if (this.mark > 2) { this.mark = 0; } }, // 左点 moveL() { this.mark--; if (this.mark < 0) { this.mark = 2; } } } }) </script> </body> </html>
相关文章推荐
- vue仪表盘,使用antv/G2实现简单的仪表盘效果
- 前端框架Vue(14)—— 利用 vue 过渡效果(transition)+定时器 实现轮播图通用组件
- vue中实现简单轮播效果
- 使用Vue组件实现一个简单弹窗效果
- vue_cli使用swiper插件实现轮播图效果
- ViewFlipper的简单使用实现图片轮播效果
- 使用CollectionView简单实现轮播广告栏效果
- vue2.0使用swiper组件实现轮播效果
- vue2.0 中使用transition实现动画效果使用心得
- vue.js实现简单轮播图效果
- Vue如何使用vue-awesome-swiper实现轮播效果
- 使用translate 实现简单轮播图效果
- 使用Tesseract (OCR)实现简单的验证码识别(C#)+窗体淡入淡出效果
- jquery实现简单的banner轮播效果【实例】
- android游戏开发框架libgdx的使用(十八)—简单的AVG游戏效果实现
- Android使用ViewPager实现左右循环滑动及轮播效果
- Jquery实现简单的轮播效果(代码管用)
- 使用Handler中postDelayed方法实现广告页面无限循环轮播效果
- 使用NSTimer与iphone的简单动画,实现飘雪效果
- 使用jquery实现简单的拖动效果