Skip to content

Commit

Permalink
feat: new maxBackfaceHiddenSlides param to prevent flicker in Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
nolimits4web committed Jan 28, 2022
1 parent ae77d46 commit 8c05e6d
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/angular/src/swiper.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export class SwiperComponent implements OnInit {
@Input() breakpoints: SwiperOptions['breakpoints'];
@Input() spaceBetween: SwiperOptions['spaceBetween'];
@Input() slidesPerView: SwiperOptions['slidesPerView'];
@Input() maxBackfaceHiddenSlides: SwiperOptions['maxBackfaceHiddenSlides'];
@Input() grid: SwiperOptions['grid'];
@Input() slidesPerGroup: SwiperOptions['slidesPerGroup'];
@Input() slidesPerGroupSkip: SwiperOptions['slidesPerGroupSkip'];
Expand Down
1 change: 1 addition & 0 deletions src/angular/src/utils/params-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const paramsList = [
'breakpoints',
'_spaceBetween',
'_slidesPerView',
'maxBackfaceHiddenSlides',
'_grid',
'_slidesPerGroup',
'_slidesPerGroupSkip',
Expand Down
5 changes: 4 additions & 1 deletion src/core/core.less
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@
align-items: flex-start;
transition-property: transform, height;
}

.swiper-backface-hidden .swiper-slide {
transform: translateZ(0);
backface-visibility: hidden;
}
/* 3D Effects */
.swiper-3d {
&,
Expand Down
5 changes: 4 additions & 1 deletion src/core/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@
transition-property: transform, height;
}
}

.swiper-backface-hidden .swiper-slide {
transform: translateZ(0);
backface-visibility: hidden;
}
/* 3D Effects */
.swiper-3d {
&,
Expand Down
2 changes: 2 additions & 0 deletions src/core/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export default {
// Passive Listeners
passiveListeners: true,

maxBackfaceHiddenSlides: 10,

// NS
containerModifierClass: 'swiper-', // NEW
slideClass: 'swiper-slide',
Expand Down
8 changes: 8 additions & 0 deletions src/core/update/updateSlides.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,4 +289,12 @@ export default function updateSlides() {
if (params.watchSlidesProgress) {
swiper.updateSlidesOffset();
}

if (!isVirtual && !params.cssMode && (params.effect === 'slide' || params.effect === 'fade')) {
if (slidesLength <= params.maxBackfaceHiddenSlides) {
swiper.$el.addClass(`${params.containerModifierClass}backface-hidden`);
} else {
swiper.$el.removeClass(`${params.containerModifierClass}backface-hidden`);
}
}
}
4 changes: 4 additions & 0 deletions src/modules/virtual/virtual.less
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.swiper-virtual .swiper-slide {
-webkit-backface-visibility: hidden;
transform: translateZ(0);
}
.swiper-virtual.swiper-css-mode {
.swiper-wrapper::after {
content: '';
Expand Down
4 changes: 4 additions & 0 deletions src/modules/virtual/virtual.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.swiper-virtual .swiper-slide {
-webkit-backface-visibility: hidden;
transform: translateZ(0);
}
.swiper-virtual.swiper-css-mode {
.swiper-wrapper::after {
content: '';
Expand Down
1 change: 1 addition & 0 deletions src/react/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const paramsList = [
'breakpoints',
'_spaceBetween',
'_slidesPerView',
'maxBackfaceHiddenSlides',
'_grid',
'_slidesPerGroup',
'_slidesPerGroupSkip',
Expand Down
1 change: 1 addition & 0 deletions src/svelte/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const paramsList = [
'breakpoints',
'_spaceBetween',
'_slidesPerView',
'maxBackfaceHiddenSlides',
'_grid',
'_slidesPerGroup',
'_slidesPerGroupSkip',
Expand Down
1 change: 1 addition & 0 deletions src/vue/params-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const paramsList = [
'breakpoints',
'_spaceBetween',
'_slidesPerView',
'maxBackfaceHiddenSlides',
'_grid',
'_slidesPerGroup',
'_slidesPerGroupSkip',
Expand Down
4 changes: 4 additions & 0 deletions src/vue/swiper-vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ declare const Swiper: DefineComponent<
type: PropType<SwiperOptions['slidesPerView']>;
default: undefined;
};
maxBackfaceHiddenSlides: {
type: NumberConstructor;
default: undefined;
};
slidesPerGroup: {
type: NumberConstructor;
default: undefined;
Expand Down
1 change: 1 addition & 0 deletions src/vue/swiper.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const Swiper = {
breakpoints: { type: Object, default: undefined },
spaceBetween: { type: Number, default: undefined },
slidesPerView: { type: [Number, String], default: undefined },
maxBackfaceHiddenSlides: { type: Number, default: undefined },
slidesPerGroup: { type: Number, default: undefined },
slidesPerGroupSkip: { type: Number, default: undefined },
slidesPerGroupAuto: { type: Boolean, default: undefined },
Expand Down

0 comments on commit 8c05e6d

Please sign in to comment.