-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider.js
49 lines (43 loc) · 1.29 KB
/
slider.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
new Vue({
el: '#app',
data: {
currentSlide: 0,
totalSlides: 0,
sliderWidth: 0,
styleSliderPos: {
transform: 'none'
}
},
mounted: function() { // No shorthand because of IE11 compatibility
this.$nextTick(function () {
this.sliderWidth = this.$refs.slide.clientWidth;
this.totalSlides = this.$refs.slideContainer.childElementCount;
});
},
methods: {
goToSlide: function(slide) {
this.currentSlide = slide;
this.updateStyles();
},
prev: function() {
this.currentSlide -= 1;
if (this.currentSlide < 0) {
this.currentSlide = this.totalSlides - 1;
}
this.updateStyles();
},
next: function() {
this.currentSlide += 1;
if (this.currentSlide > (this.totalSlides - 1)) {
this.currentSlide = 0;
}
this.updateStyles();
},
updateStyles: function() {
this.styleSliderPos = {
// No template literal because of IE11 compatiblity
transform: 'translateX(-' + this.currentSlide * this.sliderWidth + 'px)'
}
},
}
});