virtual.js 1.1 KB

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