implement basic timer
This commit is contained in:
parent
65c64ce935
commit
3e6d635650
2 changed files with 32 additions and 2 deletions
|
@ -46,6 +46,10 @@
|
||||||
vertical: {
|
vertical: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
currentIndex: {
|
||||||
|
type: Number,
|
||||||
|
default: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
|
@ -53,8 +57,10 @@
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
listWidth: 0,
|
listWidth: 0,
|
||||||
trackWidth: 0,
|
trackWidth: 0,
|
||||||
|
trackLeft: 0,
|
||||||
slides: [],
|
slides: [],
|
||||||
slideInstances: []
|
slideInstances: [],
|
||||||
|
timer: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
// events: before-change(from, to), after-change(current, from)
|
// events: before-change(from, to), after-change(current, from)
|
||||||
|
@ -69,7 +75,9 @@
|
||||||
},
|
},
|
||||||
trackStyles () {
|
trackStyles () {
|
||||||
return {
|
return {
|
||||||
width: `${this.trackWidth}px`
|
width: `${this.trackWidth}px`,
|
||||||
|
transform: `translate3d(-${this.trackLeft}px, 0px, 0px)`,
|
||||||
|
transition: `transform 500ms ${this.easing}`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -134,6 +142,17 @@
|
||||||
this.listWidth = parseInt(getStyle(this.$el, 'width'));
|
this.listWidth = parseInt(getStyle(this.$el, 'width'));
|
||||||
this.updatePos();
|
this.updatePos();
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
setAutoplay () {
|
||||||
|
if (this.autoplay) {
|
||||||
|
this.timer = window.setInterval(() => {
|
||||||
|
this.currentIndex ++;
|
||||||
|
if (this.currentIndex === this.slides.length) this.currentIndex = 0;
|
||||||
|
this.trackLeft = this.currentIndex * this.listWidth;
|
||||||
|
}, this.autoplaySpeed);
|
||||||
|
} else {
|
||||||
|
window.clearInterval(this.timer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
compiled () {
|
compiled () {
|
||||||
|
@ -153,6 +172,14 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
autoplay () {
|
||||||
|
this.setAutoplay();
|
||||||
|
},
|
||||||
|
current () {
|
||||||
|
this.switch(this.current);
|
||||||
|
}
|
||||||
|
},
|
||||||
ready () {
|
ready () {
|
||||||
this.handleResize();
|
this.handleResize();
|
||||||
window.addEventListener('resize', this.handleResize, false);
|
window.addEventListener('resize', this.handleResize, false);
|
||||||
|
|
|
@ -27,11 +27,14 @@
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
display: block;
|
display: block;
|
||||||
|
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-item {
|
&-item {
|
||||||
float: left;
|
float: left;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
min-height: 1px;
|
min-height: 1px;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue