中文 | English
##vue-slider.js
vue-slider,一个简单的滑动组件,配置简单,支持自适应/全屏+按钮+分页,同时兼容移动端和PC端
###目前已实现
- 全屏自适应
- 移动端兼容
- 垂直滚动
- 定时自动切换
- 不定宽度滚动
- 无缝循环滚动
###未来将实现
- 渐变滚动
- 视差效果
###例子
###快速开始使用
通过以下demo来实现
###app.vue父级组件
<template>
<slider :pages="someList" :sliderinit="sliderinit">
<!-- slot -->
</slider>
</template>
<script>
import slider from './slider'// 引入slider组件
export default {
el: '#app',
data () {
return {
//图片列表[arr]
pages:[
{
title: '',
style:{
background:'url(src/img/testimg-1.jpg)'
}
},
{
title: '',
style:{
background:'url(src/img/testimg-2.jpg)'
}
},
{
title: 'slide3',
style:{
background:'#4bbfc3',
},
}
],
//滑动配置[obj]
sliderinit: {
// 写了一些无需配置的项,下个版本会放到slider设定默认值
currentPage: 0,//当前页码
start: {},//默认需要书写,存放点击位置
end: {},//默认需要书写,存放点击位置
tracking: false,//swipestart状态判断
thresholdDistance: 500,//滑动判定距离
thresholdTime: 100,//滑动判定时间
autoplay:1000,//自动滚动[ms]
loop:true//循环滚动
direction:'vertical'//方向设置,垂直滚动
}
}
},
components: {
slider
}
}
</script>
###pages/初始化参数
Option | Type | Default | Description |
---|---|---|---|
title |
string | - | 当前设置为每页的标题,未来将直接输出html |
style |
obj | - | 直接作用在每个item上的style样式,可以输出背景图,背景色,每项宽度可自定义,自动切换为不定宽滚动 |
Option | Type | Default | Description |
---|---|---|---|
direction |
string | 'horizontal' | 方向设置,默认为水平滚动('horizontal'),可设置为垂直滚动('vertical') |
currentPage |
number | - | 当前为第几页 |
thresholdDistance |
number | - | 滑动距离阈值 |
thresholdTime |
number | - | 滑动时间阈值 |
autoplay |
number[ms] | - | 自动播放:时间[ms] |
loop |
boolean | false | 循环滚动 |
Method | Parameters | Description | Example |
---|---|---|---|
slideTo |
number | 滑动到(number)页 | this.$broadcast('slideTo', num) |
slideNext |
- | 滑动到下一页 | this.$broadcast('slideNext') |
slideTo |
- | 滑动到上一页 | this.$broadcast('slidePre') |
Method | Parameters | Description | Example |
---|---|---|---|
slide |
number | 当前滑动到第(number)页 | vm.$on('slide', function(pagenum){console.log(pagenum)}) |
###有更好的想法? 欢迎来留下你的意见:warpcgd#1
###BUG?oh no! 可以在这里提交,会尽快处理:warpcgd#2