Skip to content

Commit 7d5cb5c

Browse files
csmoakpax8quinnlangille
authored andcommitted
feat: add watcher to Autoplay Prop (#344)
* fix(carousel): flush the slides left when they don't fill the width (#323) * fix(carousel): Flush the slides left when they don't fill the width (#323) When there are too few slides to fill the row, with scrollPerPage, the slides were flushed right instead of left. By bounding maxOffest to a minimum of 0, the slides are aligned on the left-hand-side Fix #323 * style(play): Use capitals in tests for consistency * v0.16.1 * chore: build * feat(standard): watch autoplay prop and enable/disable autoplay
1 parent a92a910 commit 7d5cb5c

File tree

5 files changed

+48
-7
lines changed

5 files changed

+48
-7
lines changed

dist/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/themes/vue/source/js/vue-carousel.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-carousel",
3-
"version": "0.16.0",
3+
"version": "0.16.2",
44
"description": "A flexible, responsive, touch-friendly carousel for Vue.js",
55
"main": "dist/vue-carousel.min.js",
66
"scripts": {

play/index.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ play("Carousel", module)
5555
h, containerWidth, [h(Carousel, {}, generateSlideImages(h))]
5656
)
5757
)
58+
.add("Too few per page", h => createContainer(
59+
h, containerWidth, [h(Carousel, { props: { perPage: 10, scrollPerPage: false } }, generateSlideImages(h))]
60+
)
61+
)
5862
.add("3 per page", h => createContainer(
5963
h, containerWidth, [h(Carousel, { props: { perPage: 3 } }, generateSlideImages(h))]
6064
)
@@ -98,6 +102,35 @@ play("Carousel", module)
98102
h, containerWidth, [h(Carousel, { props: { autoplay: true, autoplayHoverPause: true } }, generateSlideImages(h))]
99103
)
100104
)
105+
.add("Autoplay, Pause/Resume", {
106+
template:
107+
`<div style="width: 100%; display: flex; justify-content: center; margin-top: 40px;">
108+
<carousel style="width: 500px;" :autoplay="autoplay" :loop="true">
109+
<slide v-for="slide in slideCount" :key="slide">
110+
<img style="width: 100%;" src="https://res.cloudinary.com/ssenseweb/image/upload/b_white,c_lpad,g_south,h_1086,w_724/c_scale,h_560/v588/171924M176006_1.jpg" />
111+
</slide>
112+
</carousel>
113+
<div style="float: left">
114+
<pre>Autoplay Status: {{ autoplay }}</pre>
115+
<button v-on:click="toggleAutoplay()">Toggle Autoplay</button>
116+
</div>
117+
</div>`,
118+
components: {
119+
Carousel,
120+
Slide
121+
},
122+
data() {
123+
return {
124+
autoplay: true,
125+
slideCount: 8
126+
}
127+
},
128+
methods: {
129+
toggleAutoplay() {
130+
this.autoplay = !this.autoplay;
131+
},
132+
}
133+
})
101134
.add("Dynamic, add or remove slides", {
102135
template:
103136
`<div style="width: 100%; display: flex; justify-content: center; margin-top: 40px;">

src/Carousel.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ export default {
352352
currentPage(val) {
353353
this.$emit("pageChange", val);
354354
this.$emit("input", val);
355+
},
356+
autoplay(val) {
357+
if (val === false) {
358+
this.pauseAutoplay();
359+
} else {
360+
this.restartAutoplay();
361+
}
355362
}
356363
},
357364
computed: {
@@ -424,9 +431,10 @@ export default {
424431
* @return {Number}
425432
*/
426433
maxOffset() {
427-
return (
434+
return Math.max(
428435
this.slideWidth * (this.slideCount - this.currentPerPage) -
429-
this.spacePadding * this.spacePaddingMaxOffsetFactor
436+
this.spacePadding * this.spacePaddingMaxOffsetFactor,
437+
0
430438
);
431439
},
432440
/**

0 commit comments

Comments
 (0)