diff --git a/src/modules/grid/grid.js b/src/modules/grid/grid.js index 9a3bfbf20..ba3bfcbd1 100644 --- a/src/modules/grid/grid.js +++ b/src/modules/grid/grid.js @@ -23,7 +23,6 @@ export default function Grid({ swiper, extendParams }) { const initSlides = (slidesLength) => { const { slidesPerView } = swiper.params; const { rows, fill } = swiper.params.grid; - slidesPerRow = slidesNumberEvenToRows / rows; numFullColumns = Math.floor(slidesLength / rows); if (Math.floor(slidesLength / rows) === slidesLength / rows) { slidesNumberEvenToRows = slidesLength; @@ -33,6 +32,7 @@ export default function Grid({ swiper, extendParams }) { if (slidesPerView !== 'auto' && fill === 'row') { slidesNumberEvenToRows = Math.max(slidesNumberEvenToRows, slidesPerView * rows); } + slidesPerRow = slidesNumberEvenToRows / rows; }; const updateSlide = (i, slide, slidesLength, getDirectionLabel) => { @@ -72,6 +72,8 @@ export default function Grid({ swiper, extendParams }) { row = Math.floor(i / slidesPerRow); column = i - row * slidesPerRow; } + slide.row = row; + slide.column = column; slide.style[getDirectionLabel('margin-top')] = row !== 0 ? spaceBetween && `${spaceBetween}px` : ''; }; diff --git a/src/shared/process-lazy-preloader.js b/src/shared/process-lazy-preloader.js index 68d767005..192bfaa29 100644 --- a/src/shared/process-lazy-preloader.js +++ b/src/shared/process-lazy-preloader.js @@ -25,6 +25,19 @@ export const preload = (swiper) => { ? swiper.slidesPerViewDynamic() : Math.ceil(swiper.params.slidesPerView); const activeIndex = swiper.activeIndex; + if (swiper.params.grid && swiper.params.grid.rows > 1) { + const activeColumn = activeIndex; + const preloadColumns = [activeColumn - amount]; + preloadColumns.push( + ...Array.from({ length: amount }).map((_, i) => { + return activeColumn + slidesPerView + i; + }), + ); + swiper.slides.forEach((slideEl, i) => { + if (preloadColumns.includes(slideEl.column)) unlazy(swiper, i); + }); + return; + } const slideIndexLastInView = activeIndex + slidesPerView - 1; if (swiper.params.rewind || swiper.params.loop) { for (let i = activeIndex - amount; i <= slideIndexLastInView + amount; i += 1) {