This repository has been archived by the owner on Apr 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
57 lines (46 loc) · 1.58 KB
/
main.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
50
51
52
53
54
55
56
57
(function(Polymer){
'use strict';
new Polymer('slider-component', {
ready: function() {
this.images = Array.prototype.slice.call(this.querySelectorAll('img'));
if (!this.start && parseInt(this.start, 10) !== 0) {
this.start = 0;
this.current = parseInt(this.start, 10);
}
var container = this.$.container;
for (var img in this.images) {
var currentImg = parseInt(img, 10);
if (currentImg === this.current) {
this.images[currentImg].classList.add('show');
}
this.images[currentImg].classList.add('slider-img');
container.appendChild(this.images[img]);
}
},
slide: function(evt) {
var next = evt.target.dataset.img;
this.current = parseInt(this.current, 10);
switch (next) {
case 'left':
this.images[this.current].classList.remove('show');
this.current = this.current === 0 ? this.images.length - 1 : this.current - 1;
this.images[this.current].classList.add('show');
break;
case 'right':
this.images[this.current].classList.remove('show');
this.current = this.current === this.images.length - 1 ? 0 : this.current + 1;
this.images[this.current].classList.add('show');
break;
default:
this.images[this.current].classList.remove('show');
this.current = next;
this.images[this.current].classList.add('show');
break;
}
this.applyAccent();
},
applyAccent: function() {
//
}
});
})(window.Polymer);