Skip to content

Commit

Permalink
feat(virtual): better support for effects rather than slide
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Feb 26, 2022
1 parent 69a8870 commit 2dae84f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/modules/virtual/virtual.js
@@ -1,7 +1,7 @@
import $ from '../../shared/dom.js';
import { setCSSProperty } from '../../shared/utils.js';

export default function Virtual({ swiper, extendParams, on }) {
export default function Virtual({ swiper, extendParams, on, emit }) {
extendParams({
virtual: {
enabled: false,
Expand Down Expand Up @@ -88,13 +88,15 @@ export default function Virtual({ swiper, extendParams, on }) {
if (swiper.lazy && swiper.params.lazy.enabled) {
swiper.lazy.load();
}
emit('virtualUpdate');
}

if (previousFrom === from && previousTo === to && !force) {
if (swiper.slidesGrid !== previousSlidesGrid && offset !== previousOffset) {
swiper.slides.css(offsetProp, `${offset}px`);
}
swiper.updateProgress();
emit('virtualUpdate');
return;
}
if (swiper.params.virtual.renderExternal) {
Expand All @@ -112,6 +114,8 @@ export default function Virtual({ swiper, extendParams, on }) {
});
if (swiper.params.virtual.renderExternalUpdate) {
onRendered();
} else {
emit('virtualUpdate');
}
return;
}
Expand Down
13 changes: 13 additions & 0 deletions src/shared/effect-init.js
Expand Up @@ -21,4 +21,17 @@ export default function effectInit(params) {
if (swiper.params.effect !== effect) return;
setTransition(duration);
});

let requireUpdateOnVirtual;
on('virtualUpdate', () => {
if (!swiper.slides.length) {
requireUpdateOnVirtual = true;
}
requestAnimationFrame(() => {
if (requireUpdateOnVirtual && swiper.slides.length) {
setTranslate();
requireUpdateOnVirtual = false;
}
});
});
}

0 comments on commit 2dae84f

Please sign in to comment.