1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-30 08:21:15 +02:00

Option to disable looping

#56
This commit is contained in:
Antonio Laguna
2017-03-12 22:30:59 +01:00
parent a8734a57d3
commit a8031db1f2
2 changed files with 14 additions and 2 deletions

View File

@@ -25,6 +25,7 @@ WebSlides constructor accepts an object with options.
|-----------|----------------|-----------|-------------------------------------------------------------------------------| |-----------|----------------|-----------|-------------------------------------------------------------------------------|
| `autoslide` | `number` or `boolean` | `false` | Amount of milliseconds to wait to go to next slide automatically. | | `autoslide` | `number` or `boolean` | `false` | Amount of milliseconds to wait to go to next slide automatically. |
| `changeOnClick` | `boolean` | `false` | If true, clicking on the page will go to the next slide unless it's a clickable element. See [ClickToNav docs](./click-to-nav.md) for more info. | | `changeOnClick` | `boolean` | `false` | If true, clicking on the page will go to the next slide unless it's a clickable element. See [ClickToNav docs](./click-to-nav.md) for more info. |
| `loop` | `boolean` | true | Lets WebSlides loop the slides so once it reaches the end, going next will make it go to the first slide. |
| `minWheelDelta` | `number` | `40` | Controls the amount of scroll needed to trigger a navigation. Lower this number to decrease the scroll resistance. | | `minWheelDelta` | `number` | `40` | Controls the amount of scroll needed to trigger a navigation. Lower this number to decrease the scroll resistance. |
| `scrollWait` | `number` | `450` | Controls the amount of time needed to wait for a scroll transition to happen again. | | `scrollWait` | `number` | `450` | Controls the amount of time needed to wait for a scroll transition to happen again. |
| `slideOffset` | `number` | `50` | Amount of sliding needed to trigger a new navigation. | | `slideOffset` | `number` | `50` | Amount of sliding needed to trigger a new navigation. |

View File

@@ -30,6 +30,7 @@ export default class WebSlides {
* autosliding by said amount of miliseconds. * autosliding by said amount of miliseconds.
* @param {boolean} changeOnClick If true, it will allow * @param {boolean} changeOnClick If true, it will allow
* clicking on any place to change the slide. * clicking on any place to change the slide.
* @param {boolean} loop Whether to go to first slide from last one or not.
* @param {number} minWheelDelta Controls the amount of needed scroll to * @param {number} minWheelDelta Controls the amount of needed scroll to
* trigger navigation. * trigger navigation.
* @param {number} scrollWait Controls the amount of time to wait till * @param {number} scrollWait Controls the amount of time to wait till
@@ -40,6 +41,7 @@ export default class WebSlides {
constructor({ constructor({
autoslide = false, autoslide = false,
changeOnClick = false, changeOnClick = false,
loop = true,
minWheelDelta = 40, minWheelDelta = 40,
scrollWait = 450, scrollWait = 450,
slideOffset = 50 slideOffset = 50
@@ -100,6 +102,7 @@ export default class WebSlides {
this.options = { this.options = {
autoslide, autoslide,
changeOnClick, changeOnClick,
loop,
minWheelDelta, minWheelDelta,
scrollWait, scrollWait,
slideOffset slideOffset
@@ -178,7 +181,7 @@ export default class WebSlides {
/** /**
* Goes to a given slide. * Goes to a given slide.
* @param {!number} slideI The slide index. * @param {!number} slideI The slide index.
* @param {?boolean} forward Whether we're forcing moving forward/backwards. * @param {?boolean=} forward Whether we're forcing moving forward/backwards.
* This parameter is used only from the goNext, goPrev functions to adjust the * This parameter is used only from the goNext, goPrev functions to adjust the
* scroll animations. * scroll animations.
*/ */
@@ -317,6 +320,10 @@ export default class WebSlides {
let nextIndex = this.currentSlideI_ + 1; let nextIndex = this.currentSlideI_ + 1;
if (nextIndex >= this.maxSlide_) { if (nextIndex >= this.maxSlide_) {
if (!this.options.loop) {
return;
}
nextIndex = 0; nextIndex = 0;
} }
@@ -330,6 +337,10 @@ export default class WebSlides {
let prevIndex = this.currentSlideI_ - 1; let prevIndex = this.currentSlideI_ - 1;
if (prevIndex < 0) { if (prevIndex < 0) {
if (!this.options.loop) {
return;
}
prevIndex = this.maxSlide_ - 1; prevIndex = this.maxSlide_ - 1;
} }
@@ -391,7 +402,7 @@ export default class WebSlides {
/** /**
* Starts autosliding all the slides if it's not currently doing it and the * Starts autosliding all the slides if it's not currently doing it and the
* autoslide option was a number greater than 0. * autoslide option was a number greater than 0.
* @param {?number} time Amount of milliseconds to wait to go to next slide * @param {?number=} time Amount of milliseconds to wait to go to next slide
* automatically. * automatically.
*/ */
play(time) { play(time) {