preloadImages.js 777 B

12345678910111213141516171819
  1. export default function preloadImages() {
  2. const swiper = this;
  3. swiper.imagesToLoad = swiper.$el.find('img');
  4. function onReady() {
  5. if (typeof swiper === 'undefined' || swiper === null || !swiper || swiper.destroyed) return;
  6. if (swiper.imagesLoaded !== undefined) swiper.imagesLoaded += 1;
  7. if (swiper.imagesLoaded === swiper.imagesToLoad.length) {
  8. if (swiper.params.updateOnImagesReady) swiper.update();
  9. swiper.emit('imagesReady');
  10. }
  11. }
  12. for (let i = 0; i < swiper.imagesToLoad.length; i += 1) {
  13. const imageEl = swiper.imagesToLoad[i];
  14. swiper.loadImage(imageEl, imageEl.currentSrc || imageEl.getAttribute('src'), imageEl.srcset || imageEl.getAttribute('srcset'), imageEl.sizes || imageEl.getAttribute('sizes'), true, onReady);
  15. }
  16. }