Skip to content

Commit

Permalink
fix(virtual): fix removing nested slides
Browse files Browse the repository at this point in the history
fixes #7005
  • Loading branch information
nolimits4web committed Sep 6, 2023
1 parent ea39c33 commit c3321e1
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/modules/virtual/virtual.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ export default function Virtual({ swiper, extendParams, on, emit }) {
slideEl.innerHTML = slide;
}

if (params.cache) swiper.virtual.cache[index] = slideEl;
if (params.cache) {
swiper.virtual.cache[index] = slideEl;
}
return slideEl;
}

Expand Down Expand Up @@ -161,18 +163,20 @@ export default function Virtual({ swiper, extendParams, on, emit }) {
};

if (force) {
swiper.slidesEl
.querySelectorAll(`.${swiper.params.slideClass}, swiper-slide`)
swiper.slides
.filter((el) => el.matches(`.${swiper.params.slideClass}, swiper-slide`))
.forEach((slideEl) => {
slideEl.remove();
});
} else {
for (let i = previousFrom; i <= previousTo; i += 1) {
if (i < from || i > to) {
const slideIndex = getSlideIndex(i);
swiper.slidesEl
.querySelectorAll(
`.${swiper.params.slideClass}[data-swiper-slide-index="${slideIndex}"], swiper-slide[data-swiper-slide-index="${slideIndex}"]`,
swiper.slides
.filter((el) =>
el.matches(
`.${swiper.params.slideClass}[data-swiper-slide-index="${slideIndex}"], swiper-slide[data-swiper-slide-index="${slideIndex}"]`,
),
)
.forEach((slideEl) => {
slideEl.remove();
Expand Down

0 comments on commit c3321e1

Please sign in to comment.