Skip to content

Commit 206c87f

Browse files
author
wanghongyuneurotoxin
committed
add autoscroll
1 parent 416fe0b commit 206c87f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

docs/slider/slider.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ function Slider(options) {
33
wrap: options.wrap,
44
inner: options.inner,
55
dots: options.dots,
6-
speed: options.speed
6+
speed: options.speed,
7+
auto: options.auto
78
}
89

910
this.$slider = document.querySelector(options.wrap);
@@ -13,6 +14,8 @@ function Slider(options) {
1314
this.resize();
1415

1516
this.runScroll();
17+
18+
this.autoScroll();
1619
}
1720

1821
Slider.prototype = {
@@ -81,12 +84,25 @@ Slider.prototype = {
8184
}
8285
}
8386
});
87+
},
88+
autoScroll: function() {
89+
if (!this.options.auto) {
90+
return
91+
}
92+
var that = this;
93+
console.log(that.slider)
94+
var page = that.slider.getCurrentPage().pageX;
95+
96+
setInterval(function(){
97+
that.slider.next()
98+
}, this.options.auto)
8499
}
85100
}
86101

87102
new Slider({
88103
wrap: '#slider',
89104
inner: '.content',
90105
dots: '.dots',
91-
speed: 400
106+
speed: 400,
107+
auto: 2000
92108
});

0 commit comments

Comments
 (0)