lc-ep-slider

ep滑块效果的 slider 组件,用于丰富 slide,包括商品橱窗,图片列表等

注意事项

假如子组件有点击事件,在 Android 由于 此约束,目前需要在子元素里面绑定对应事件,提供了 lc-pan-cell

效果

使用方法

<template>
<div class="wxc-demo">
<scroller class="scroller">
<title title="lc-ep-slider"></title>
<category title="基础使用"></category>
<div class="wrapper">
<lc-ep-slider :slider-id="sliderId"
:card-length='cardLength'
:card-s="cardSize"
:select-index="2"
@LcEpSliderCurrentIndexSelected="LcEpSliderCurrentIndexSelected">

<!--自动生成demo-->
<div v-for="(v,index) in [1,2,3,4,5]"
:key="index"
:slot="`card${index}_${sliderId}`"
:class="['slider',`slider${index}`]"
:accessible="true"
:aria-label="`这里是第${index + 1}个滑块`">
<text class="text">这里是第{{index + 1}}个滑块</text>
</div>
</lc-ep-slider>
</div>
<category title="Android点击滑动冲突"></category>
<div class="wrapper">
<lc-ep-slider :slider-id="autoSliderId"
:card-length='cardLength'
ref="lc-ep-slider"
:card-s="cardSize"
:auto-play="true"
:select-index="2"
@LcEpSliderCurrentIndexSelected="LcEpSliderCurrentIndexSelected">
<!--自动生成demo-->
<lc-pan-item v-for="(v,index) in [1,2,3,4,5]"
:key="index"
:ext-id="index"
:class="['slider',`slider${index}`]"
@LcPanItemPan="LcPanItemPan"
@LcPanItemClick="LcPanItemClick(index)"
:slot="`card${index}_${autoSliderId}`"
:accessible="true"
:aria-label="`这里是第${index + 1}个滑块`">
<text class="text" >这里是第{{index + 1}}个滑块</text>
</lc-pan-item>
</lc-ep-slider>
<div class="btn" @click="onClick">
<text class="btn-text">手动切换2滑块</text>
</div>
</div>
</scroller>
</div>
</template>

<style scoped>
.wxc-demo {
position: absolute;
top: 0;
right: 0;
left: 0;
bottom: 0;
background-color: #fff;
}

.scroller {
flex: 1;
}

.wrapper {
padding-top: 40px;
}

.text {
font-size: 32px;
color: #333333;
}

.btn {
width: 250px;
height: 80px;
margin-left: 250px;
background-color: #635147;
align-items: center;
justify-content: center;
margin-bottom: 40px;
}

.btn-text {
font-size: 30px;
color: #ffffff;
}

.slider {
width: 400px;
height: 300px;
background-color: #0064c8;
align-items: center;
justify-content: center;
}

.slider1 {
background-color: #0080ff;
}

.slider2 {
background-color: #62b0ff;
}

.slider3 {
background-color: #a2d0ff;
}

.slider4 {
background-color: #cce6ff;
}
</style>

<script>
import Light from 'light'
const modal = Light.requireModule('modal');

import LcEpSlider from 'lighting-ui/packages/lc-ep-slider';
import LcPanItem from 'lighting-ui/packages/lc-pan-item';
import Utils from 'lighting-ui/packages/utils';
import Title from 'lighting-ui/packages/_mods/title.vue';
import Category from 'lighting-ui/packages/_mods/category.vue';

export default {
components: { Title, Category, LcEpSlider, LcPanItem },
data: () => ({
sliderId: 1,
autoSliderId: 2,
cardLength: 5,
cardSize: {
width: 400,
height: 300,
spacing: 0,
scale: 0.8
}
}),
methods: {
LcEpSliderCurrentIndexSelected (e) {
// const index = e.currentIndex;
// console.log(index);
},
onClick () {
// 手动切换到第2张
this.$refs['lc-ep-slider'].manualSetPage(1);
},
LcPanItemPan (e) {
console.log(22222)
if (Utils.env.supportsEBForAndroid()) {
this.$refs['lc-ep-slider'].clearAutoPlay();
this.$refs['lc-ep-slider'].bindExp(e.element)
}
},
LcPanItemClick (e) {
modal.toast({
message: e,
duration: 1
})
}
}
}
</script>

可配置参数

Prop Type Required Default Description
slider-id Number Y 1 slider的id,避免页面多个ep-slider导致获取错误
card-length Number Y 1 slider中item的数量
select-index Number N 0 默认突出item的index
enable-swipe Boolean N true 是否需要滑动效果
container-s Object Y {position: 'relative',width: 750,height: 352,overflow: 'hidden'} 包裹容器的样式
card-s Object Y {width: 360,height: 300,spacing: 0,scale: 0.75} item容器的样式
auto-play Boolean N false 是否需要自动播放
interval Number N 1200 自动播放时候的间隔

API说明

//ios下当放在list中,cell被回收后,导致下次appear的时候,手势失效了,需要再手动调用api,重新绑定下pan事件
// 直接在lc-ep-slider组件上面绑定ref="lc-ep-slider"
this.$refs['lc-ep-slider'].rebind();

主动触发设置

// 直接在lc-ep-slider组件上面绑定ref="lc-ep-slider",然后调用即可
// 譬如设置第二张
this.$refs['lc-ep-slider'].manualSetPage(1);

事件回调

//当前滑块被选中的回调
`v-on:LcEpSliderCurrentIndexSelected="LcEpSliderCurrentIndexSelected"`