updated autoplay and wrote tests

This commit is contained in:
Rijn 2017-01-16 04:28:34 -06:00
parent 3e6d635650
commit bfc11079e2
3 changed files with 49 additions and 14 deletions

View file

@ -1,5 +1,5 @@
<template>
<div :class="prefixCls" v-bind:style="styles">{{width}}<slot></slot></div>
<div :class="prefixCls" v-bind:style="styles"><slot></slot></div>
</template>
<script>
const prefixCls = 'ivu-carousel-item';

View file

@ -143,15 +143,18 @@
this.updatePos();
});
},
slide () {
this.trackLeft = this.currentIndex * this.listWidth;
},
setAutoplay () {
window.clearInterval(this.timer);
if (this.autoplay) {
this.timer = window.setInterval(() => {
this.currentIndex ++;
if (this.currentIndex === this.slides.length) this.currentIndex = 0;
this.trackLeft = this.currentIndex * this.listWidth;
let index = this.currentIndex;
index ++;
if (index === this.slides.length) index = 0;
this.currentIndex = index;
}, this.autoplaySpeed);
} else {
window.clearInterval(this.timer);
}
}
},
@ -176,12 +179,18 @@
autoplay () {
this.setAutoplay();
},
current () {
this.switch(this.current);
autoplaySpeed () {
this.setAutoplay();
},
currentIndex () {
this.$nextTick(() => {
this.slide();
});
}
},
ready () {
this.handleResize();
this.setAutoplay();
window.addEventListener('resize', this.handleResize, false);
},
beforeDestroy () {