Skip to content

Commit

Permalink
feat: add watcher to Autoplay Prop (#344)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
csmoakpax8 authored and quinnlangille committed Dec 18, 2018
1 parent a92a910 commit 7d5cb5c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
4 changes: 2 additions & 2 deletions dist/vue-carousel.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/themes/vue/source/js/vue-carousel.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-carousel",
"version": "0.16.0",
"version": "0.16.2",
"description": "A flexible, responsive, touch-friendly carousel for Vue.js",
"main": "dist/vue-carousel.min.js",
"scripts": {
Expand Down
33 changes: 33 additions & 0 deletions play/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ play("Carousel", module)
h, containerWidth, [h(Carousel, {}, generateSlideImages(h))]
)
)
.add("Too few per page", h => createContainer(
h, containerWidth, [h(Carousel, { props: { perPage: 10, scrollPerPage: false } }, generateSlideImages(h))]
)
)
.add("3 per page", h => createContainer(
h, containerWidth, [h(Carousel, { props: { perPage: 3 } }, generateSlideImages(h))]
)
Expand Down Expand Up @@ -98,6 +102,35 @@ play("Carousel", module)
h, containerWidth, [h(Carousel, { props: { autoplay: true, autoplayHoverPause: true } }, generateSlideImages(h))]
)
)
.add("Autoplay, Pause/Resume", {
template:
`<div style="width: 100%; display: flex; justify-content: center; margin-top: 40px;">
<carousel style="width: 500px;" :autoplay="autoplay" :loop="true">
<slide v-for="slide in slideCount" :key="slide">
<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" />
</slide>
</carousel>
<div style="float: left">
<pre>Autoplay Status: {{ autoplay }}</pre>
<button v-on:click="toggleAutoplay()">Toggle Autoplay</button>
</div>
</div>`,
components: {
Carousel,
Slide
},
data() {
return {
autoplay: true,
slideCount: 8
}
},
methods: {
toggleAutoplay() {
this.autoplay = !this.autoplay;
},
}
})
.add("Dynamic, add or remove slides", {
template:
`<div style="width: 100%; display: flex; justify-content: center; margin-top: 40px;">
Expand Down
12 changes: 10 additions & 2 deletions src/Carousel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,13 @@ export default {
currentPage(val) {
this.$emit("pageChange", val);
this.$emit("input", val);
},
autoplay(val) {
if (val === false) {
this.pauseAutoplay();
} else {
this.restartAutoplay();
}
}
},
computed: {
Expand Down Expand Up @@ -424,9 +431,10 @@ export default {
* @return {Number}
*/
maxOffset() {
return (
return Math.max(
this.slideWidth * (this.slideCount - this.currentPerPage) -
this.spacePadding * this.spacePaddingMaxOffsetFactor
this.spacePadding * this.spacePaddingMaxOffsetFactor,
0
);
},
/**
Expand Down

0 comments on commit 7d5cb5c

Please sign in to comment.