updateClickedSlide.js 848 B

1234567891011121314151617181920212223242526272829303132333435
  1. export default function updateClickedSlide(e) {
  2. const swiper = this;
  3. const params = swiper.params;
  4. const slide = swiper.slides[e];
  5. let slideFound = false;
  6. let slideIndex;
  7. if (slide) {
  8. for (let i = 0; i < swiper.slides.length; i += 1) {
  9. if (swiper.slides[i] === slide) {
  10. slideFound = true;
  11. slideIndex = i;
  12. break;
  13. }
  14. }
  15. }
  16. if (slide && slideFound) {
  17. swiper.clickedSlide = slide;
  18. if (swiper.virtual && swiper.params.virtual.enabled) {
  19. swiper.clickedIndex = parseInt($(slide).attr('data-swiper-slide-index'), 10);
  20. } else {
  21. swiper.clickedIndex = slideIndex;
  22. }
  23. } else {
  24. swiper.clickedSlide = undefined;
  25. swiper.clickedIndex = undefined;
  26. return;
  27. }
  28. if (params.slideToClickedSlide && swiper.clickedIndex !== undefined && swiper.clickedIndex !== swiper.activeIndex) {
  29. swiper.slideToClickedSlide();
  30. }
  31. }