effect-virtual-transition-end.mjs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { k as elementTransitionEnd } from './utils.mjs';
  2. function effectVirtualTransitionEnd(_ref) {
  3. let {
  4. swiper,
  5. duration,
  6. transformElements,
  7. allSlides
  8. } = _ref;
  9. const {
  10. activeIndex
  11. } = swiper;
  12. const getSlide = el => {
  13. if (!el.parentElement) {
  14. // assume shadow root
  15. const slide = swiper.slides.filter(slideEl => slideEl.shadowRoot && slideEl.shadowRoot === el.parentNode)[0];
  16. return slide;
  17. }
  18. return el.parentElement;
  19. };
  20. if (swiper.params.virtualTranslate && duration !== 0) {
  21. let eventTriggered = false;
  22. let transitionEndTarget;
  23. if (allSlides) {
  24. transitionEndTarget = transformElements;
  25. } else {
  26. transitionEndTarget = transformElements.filter(transformEl => {
  27. const el = transformEl.classList.contains('swiper-slide-transform') ? getSlide(transformEl) : transformEl;
  28. return swiper.getSlideIndex(el) === activeIndex;
  29. });
  30. }
  31. transitionEndTarget.forEach(el => {
  32. elementTransitionEnd(el, () => {
  33. if (eventTriggered) return;
  34. if (!swiper || swiper.destroyed) return;
  35. eventTriggered = true;
  36. swiper.animating = false;
  37. const evt = new window.CustomEvent('transitionend', {
  38. bubbles: true,
  39. cancelable: true
  40. });
  41. swiper.wrapperEl.dispatchEvent(evt);
  42. });
  43. });
  44. }
  45. }
  46. export { effectVirtualTransitionEnd as e };