virtual.js 988 B

123456789101112131415161718192021222324252627282930313233
  1. import React from 'react';
  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(swiper, slides, virtualData) {
  15. if (!virtualData) return null;
  16. const style = swiper.isHorizontal() ? {
  17. [swiper.rtlTranslate ? 'right' : 'left']: `${virtualData.offset}px`
  18. } : {
  19. top: `${virtualData.offset}px`
  20. };
  21. return slides.filter((child, index) => index >= virtualData.from && index <= virtualData.to).map(child => {
  22. return /*#__PURE__*/React.cloneElement(child, {
  23. swiper,
  24. style
  25. });
  26. });
  27. }
  28. export { renderVirtual, updateOnVirtualData };