slideToLoop.js 974 B

123456789101112131415161718192021222324252627282930313233
  1. export default function slideToLoop(index = 0, speed = this.params.speed, runCallbacks = true, internal) {
  2. if (typeof index === 'string') {
  3. /**
  4. * The `index` argument converted from `string` to `number`.
  5. * @type {number}
  6. */
  7. const indexAsNumber = parseInt(index, 10);
  8. /**
  9. * Determines whether the `index` argument is a valid `number`
  10. * after being converted from the `string` type.
  11. * @type {boolean}
  12. */
  13. const isValidNumber = isFinite(indexAsNumber);
  14. if (!isValidNumber) {
  15. throw new Error(`The passed-in 'index' (string) couldn't be converted to 'number'. [${index}] given.`);
  16. } // Knowing that the converted `index` is a valid number,
  17. // we can update the original argument's value.
  18. index = indexAsNumber;
  19. }
  20. const swiper = this;
  21. let newIndex = index;
  22. if (swiper.params.loop) {
  23. newIndex += swiper.loopedSlides;
  24. }
  25. return swiper.slideTo(newIndex, speed, runCallbacks, internal);
  26. }