virtual.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // import { h } from 'vue';
  2. function updateOnVirtualData(swiper) {
  3. if (
  4. !swiper ||
  5. swiper.destroyed ||
  6. !swiper.params.virtual ||
  7. (swiper.params.virtual && !swiper.params.virtual.enabled)
  8. ) return;
  9. swiper.updateSlides();
  10. swiper.updateProgress();
  11. swiper.updateSlidesClasses();
  12. if (swiper.lazy && swiper.params.lazy.enabled) {
  13. swiper.lazy.load();
  14. }
  15. if (swiper.parallax && swiper.params.parallax && swiper.params.parallax.enabled) {
  16. swiper.parallax.setTranslate();
  17. }
  18. }
  19. function renderVirtual(swiperRef, slides, virtualData) {
  20. if (!virtualData) return null;
  21. const style = swiperRef.isHorizontal() ? {
  22. [swiperRef.rtlTranslate ? 'right' : 'left']: `${virtualData.offset}px`,
  23. } : {
  24. top: `${virtualData.offset}px`,
  25. };
  26. return slides
  27. .filter((slide, index) => index >= virtualData.from && index <= virtualData.to)
  28. .map((slide) => {
  29. if (!slide.props) slide.props = {};
  30. if (!slide.props.style) slide.props.style = {};
  31. slide.props.swiperRef = swiperRef;
  32. slide.props.style = style;
  33. return h(slide.type, {
  34. ...slide.props
  35. }, slide.children);
  36. });
  37. }
  38. export {
  39. renderVirtual,
  40. updateOnVirtualData
  41. };