Skip to content

Commit

Permalink
fix(core): centeredSlides won't work when use creative-effect (#5115)
Browse files Browse the repository at this point in the history
* feat: Add transform with slidesOffsetBefore and offsetWidth

* fix: Set slidesEl orignalProgress when use without centeredSlides

* chore: use slidesSizesGrid

Co-authored-by: Vladimir Kharlampidi <[email protected]>
  • Loading branch information
nabigraphics and nolimits4web authored Oct 25, 2021
1 parent 33c411e commit 264ca64
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/modules/effect-creative/effect-creative.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,32 @@ export default function EffectCreative({ swiper, extendParams, on }) {
};

const setTranslate = () => {
const { slides } = swiper;
const { slides, $wrapperEl, slidesSizesGrid } = swiper;
const params = swiper.params.creativeEffect;
const { progressMultiplier: multiplier } = params;

const isCenteredSlides = swiper.params.centeredSlides;

if (isCenteredSlides) {
const margin = slidesSizesGrid[0] / 2 - swiper.params.slidesOffsetBefore || 0;
$wrapperEl.transform(`translateX(calc(50% - ${margin}px))`);
}

for (let i = 0; i < slides.length; i += 1) {
const $slideEl = slides.eq(i);
const slideProgress = $slideEl[0].progress;
const progress = Math.min(
Math.max($slideEl[0].progress, -params.limitProgress),
params.limitProgress,
);
const originalProgress = Math.min(
Math.max($slideEl[0].originalProgress, -params.limitProgress),
params.limitProgress,
);
let originalProgress = progress;

if (!isCenteredSlides) {
originalProgress = Math.min(
Math.max($slideEl[0].originalProgress, -params.limitProgress),
params.limitProgress,
);
}

const offset = $slideEl[0].swiperSlideOffset;
const t = [swiper.params.cssMode ? -offset - swiper.translate : -offset, 0, 0];
Expand Down

0 comments on commit 264ca64

Please sign in to comment.