Vue2原生始轮播图组件,支持宽度自适应、高度设置、轮播时间设置、左右箭头按钮控制,圆点按钮切换,以及箭头、圆点按钮是否显示。
<v-carousel :slideData="slideData" :height="450" :begin="0" :interval="3000" :dot="true" :arrow="true"></v-carousel>


话不多说直接上源码
轮播图应用页面 \components\public\home.vue
<template>
<div id="home">
<v-carousel :slideData="slideData" :height="450" :begin="0" :interval="3000" :dot="true" :arrow="true"></v-carousel>
</div>
</template>
<script> import carousel from "./public/carousel"; export default {
name: 'home',
data() {
return {
slideData:[
{
title:'这是一个Vue轮播图组件',
src:require('../assets/pic1.jpg'),
url:'/show/499'
},
{
title:'这是一个Vue轮播图组件',
src:require('../assets/pic2.jpg'),
url:'/show/499' },
{
title:'这是一个Vue轮播图组件',
src:require('../assets/pic3.jpg'),
url:'/show/499'
},
{
title:'这是一个Vue轮播图组件',
src:require('../assets/pic4.jpg'),
url:'/show/499'
},
{
title:'这是一个Vue轮播图组件',
src:require('../assets/pic5.jpg'),
url:'/show/499'
},
]
}
},
components:{
'v-carousel': carousel,
},
methods: { },
mounted() {
}
}
</script>
<style scoped>
</style>

轮播图组件页面 src\components\public\carousel.vue

<template>
<div id="carousel">
<div class="carousel" ref="carousel" v-bind:style="{height:height+'px'}">
<transition-group tag="ul" class="slide clearfix" :name="transitionName" >
<li v-for="(item,index) in slideData" :key="index" v-show="index==beginValue" v-bind:style="{height:height+'px'}" >
<router-link :to="item.url">
<img :src="item.src">
<div class="title">{{item.title}}</div>
</router-link>
</li>
</transition-group>
<div class="up" @click="up" v-show="arrow"></div>
<div class="next" @click="next" v-show="arrow"></div>
<div class="slideDot" v-show="dot">
<span v-for="(item,index) in slideData" :class="{active:index==beginValue}" @click="change(index)" :key="index"></span>
</div>
</div> </div>
</template> <script>
export default {
name: "carousel",
data(){
return{
setInterval:'',
beginValue:0,
transitionName:'slide'
}
},
beforeDestroy() {
// 组件销毁前,清除监听器
clearInterval(this.setInterval);
},
methods:{
change(key){
if(key>(this.slideData.length-1)){
key=0;
}
if(key<0){
key=this.slideData.length-1;
} this.beginValue=key;
},
autoPlay(){
//console.log(this.$refs.carousel.getBoundingClientRect().width);
this.transitionName='slide';
this.beginValue++
if(this.beginValue>=this.slideData.length){
this.beginValue=0;
return;
}
},
play(){
this.setInterval=setInterval(this.autoPlay,this.interval)
},
mouseOver(){ //鼠标进入
//console.log('over')
clearInterval(this.setInterval)
},
mouseOut(){ //鼠标离开
//console.log('out')
this.play()
},
up(){ //上一页
--this.beginValue;
this.transitionName='slideBack';
this.change(this.beginValue); },
next(){ //下一页
++this.beginValue;
this.transitionName='slide';
this.change(this.beginValue);
} },
mounted(){
var box = this.$refs.carousel; //监听对象
box.addEventListener('mouseover',()=>{
this.mouseOver();
})
box.addEventListener('mouseout',()=>{
this.mouseOut();
})
this.beginValue=this.begin;
this.play(); },
props:{
height:{
type: Number,
default: 600
},
dot:{
type: Boolean,
default: true
},
arrow:{
type: Boolean,
default: true
},
interval:{
type: Number,
default: 5000
},
begin:{
type: Number,
default: 0
},
slideData:{
type: Array,
default: function () {
return [];
} }
}
}
</script> <style scoped> .slide{position: relative;margin: 0;padding: 0; overflow: hidden;width: 100%; height:450px;}
.slide li{list-style: none;position: absolute;width: 100%; height:450px;}
.slide li img{width: 100%; height:450px;cursor:pointer}
.slide li .title{position: absolute; left:0; bottom: 0; padding: 10px 20px; width: 100%; background: rgba(0,0,0,.35);color: #fff;font-size: larger; text-align: center} .slideDot{position: absolute;z-index: 999; bottom: 60px;right:15px; }
.slideDot span{display: inline-block; width: 30px; height: 7px; background:rgba(255,255,255,.65); margin-left: 5px;}
.slideDot span.active{background:rgba(255,255,255,1);}
.up,.next{position: absolute; left:0; top: 50%; margin-top: -32px; cursor: pointer; width:64px;height: 64px;
background-repeat: no-repeat;
background-position: 50% 50%;
}
.up{background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABSklEQVRoQ9Xa220CMRCF4XMqIB0kdJASSCfpIDWlAzqAElIC6SBUMNFIywsCtB7PjX336v/k3YexTBQ+IvIC4AvAN8mTJYWWRR5rROQdwAGAIk4kt5b3lgCu4rX7l+TbUwBuxJ8B7Ej+tAd4xys47ROKiE8DRMWnACLjwwHR8aGAjPgwQFZ8CCAz3h2QHe8KqIh3A1TFuwAq46cB1fFTgA7xZkCXeBOgU/wwoFv8EKBj/GpA1/gRgJ4e7JaZdWqGtcy9j9asGilFRM9sXpcX/QH4sA7hVQA9wzkC2HRDrNoBjV7+g3aI1YCuiCFAR8QwoBvCBOiEMAO6IKYAHRDTgGqEC6AS4QaoQrgCKhDugGxECCATEQbIQoQCMhDhgGhECiASkQaIQqQCIhDpgDuI57orcQNxJqmXPoafkh24VIqIXvD4BLC3HtP8A6pfGkB3vbyXAAAAAElFTkSuQmCC");}
.next{left: auto;right:0;background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAABOElEQVRoQ9Xa0W0CQQyEYU9JqShQAXSSEgIdUAIlQAd04milezgdOiHZ4/GGN5C8/N/u060Olvy4+8nMngDuyaVC4whNLUPufjazn+XrEcAls15klgkY/y9HpACj2N3Hrn+vdk+KSAO6ERRAJ4IG6EJQAR0IOkCNKAEoEWUAFaIUoECUA6oREkAlQgaoQkgBFQg5gI1oATARbQAWohXAQLQDsogpABnENIAoYirADuILwGPvxmJGwK+ZHVbB/wfg7tv4K4A15u0gpjmBSPzQTAGIxk8ByMS3A7LxrQBGfBuAFd8CYMbLAex4KaAiXgaoipcAKuPLAdXxpQBFfBlAFV8CUMbTAep4KqAjngboiqcAOuPTgM27EmO9j8+we7cL0d9Tj5QbgDw+fQLLPc54Y+UF4BbdxczcH9Le8DFn39OvAAAAAElFTkSuQmCC");}
.up:hover{background-color: rgba(0,0,0,.3)}
.next:hover{background-color: rgba(0,0,0,.3)} /*进入过渡生效时的状态*/
.slide-enter-active{
transform:translateX(0);
transition: all 1s ease;
} /*进入开始状态*/
.slide-enter{
transform:translateX(-100%);
} /*离开过渡生效时的状态*/
.slide-leave-active{
transform:translateX(100%);
transition: all 1s ease;
} /*离开过渡的开始状态*/
.slide-leave{
transform:translateX(0);
} /*进入过渡生效时的状态*/
.slideBack-enter-active{
transform:translateX(0);
transition: all 1s ease;
} /*进入开始状态*/
.slideBack-enter{
transform:translateX(100%);
} /*离开过渡生效时的状态*/
.slideBack-leave-active{
transform:translateX(-100%);
transition: all 1s ease;
} /*离开过渡的开始状态*/
.slideBack-leave{
transform:translateX(0);
} </style>

  

Vue2 轮播图组件 slide组件的更多相关文章

  1. 2.bootstrap练习笔记-轮播图

    bootstrap练习笔记-轮播图 1.要使用轮播图,首先要将其放在一个主div里面 设置id为myCaroysel class为carousel slide 设置id是标识这个div是轮播图,等到l ...

  2. 用原生js封装轮播图

    原生js封装轮播图 对于初学js的同学来说,轮播图还是一个难点,尤其是原生js封装轮播图代码,下面是我之前做的一个轮播图项目中封装好的一些代码,有需要的同学可以看一下,有什么不懂的可以看注释,注释看不 ...

  3. React Native 之轮播图swiper组件

    注释:swiper组件是第三方组件 所以在使用之前应该先在命令行安装,然后将第三方的模块引入(第三方模块地址:https://github.com/leecade/react-native-swipe ...

  4. vue自定义轮播图组件 swiper

    1.banner 组件 components/Banner.vue <!-- 轮播图 组件 --> <template> <div class="swiper- ...

  5. bootstrap轮播图组件

    一.轮播图组件模板(官方文档) <div id="carousel-example-generic" class="carousel slide" dat ...

  6. ReactNative新手学习之路04 组件化开发轮播图swiper支持安卓和IOS

    react native 新手之路04 组件化开发轮播图swiper支持安卓和IOS npm install react-native-carousel --save git 地址Properties ...

  7. 原生JS面向对象思想封装轮播图组件

    原生JS面向对象思想封装轮播图组件 在前端页面开发过程中,页面中的轮播图特效很常见,因此我就想封装一个自己的原生JS的轮播图组件.有了这个需求就开始着手准备了,代码当然是以简洁为目标,轮播图的各个功能 ...

  8. 前端笔记之JavaScript面向对象(四)组件化开发&轮播图|俄罗斯方块实战

    一.组件化开发 1.1组件化概述 页面特效的制作,特别需要HTML.CSS有固定的布局,所以说现在越来越流行组件开发的模式,就是用JS写一个类,当你实例化这个类的时候,页面上的效果布局也能自动完成. ...

  9. reactjs-swiper react轮播图组件基于swiper

    react轮播图组件基于swiper demo地址:http://reactjs-ui.github.io/reactjs-swiper/simple.html 1. 下载安装 npm install ...

随机推荐

  1. 没有对比就没有伤害,memcache and redis

    Memcached 与 Redis 的关键性能指标比较 性能对比: Redis 只使用单核,而 Memcached 可以使用多核,所以平均每一个核上 Redis在存储小数据时比 Memcached 性 ...

  2. 1 年经验 Java 求职面试题

    从 17 年的大三暑假就在这家公司实习转正,在这家公司呆了快2年了,随着公司新一轮的融资,看起来公司离上市更近了一步,但期权池也进一步稀释,没有期权的我感觉回报更少了,另外在这家公司接触到的东西也有瓶 ...

  3. 如何激活 Trend Micro Deep Security Agent

    Deep Security 即服务包括反恶意软件保护.防火墙.入侵防御系统和完整性监视.Trend Micro Deep Security Agent (DSA) 可以配合 Deep Security ...

  4. Docker-容器数据卷

    docker容器数据卷相当于外置的移动硬盘 docker容器数据卷主要功能是:容器的持久化.容器间继承+共享数据 特点: (1)数据卷可以容器之间共享或重用数据 (2)卷中更改可以直接生效 (3)数据 ...

  5. 书籍管理系统 -----没有form组件

    urls: from django.contrib import admin from django.urls import path,re_path from first import views ...

  6. python之路——进程

    操作系统背景知识 顾名思义,进程即正在执行的一个过程.进程是对正在运行程序的一个抽象. 进程的概念起源于操作系统,是操作系统最核心的概念,也是操作系统提供的最古老也是最重要的抽象概念之一.操作系统的其 ...

  7. Centos7 下编译 Openjdk8

    本文主要介绍如何在 Centos7 下编译 Openjdk8 源码,<深入理解java虚拟机>第二版网上好多 openjdk7 的帖子,编译 jdk8 和 7 还是有些差别的,比如大家经常 ...

  8. Ubuntu18.04 vmware环境下配置静态ip

    各种linux系统发行版本配置静态ip方法各不相同,dhcp获取的话ip可能会变动,如果用xshell等工具连接的时候还要改ip,很是麻烦: 参考了网上各种配置Ubuntu18.04配置静态ip的方法 ...

  9. python29 excel写模块xlwt

    xlwt模块用于新建excel文件并写入数据. 安装 pip install xlwt 简单使用 import xlwt from datetime import datetime #样式 style ...

  10. jq实现鼠标经过出现上拉菜单

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...