better fade effect without white background / z-index problem with fast click over navigation
Hi, it is possible recode FADE animation without z-index + no white background, because slides between active slide has opacity: 0? https://swiperjs.com/demos/#fade_effect Problem with zindex is fast clicking on pagination / arrows with waitForTransition: false and speed: 2500. Animation is not smooth. Swiper this solved right way with translate3d, opacity + pointer-events: none / auto (no issue with zindex). Thank you
You can overwrite the Fading process by creating a new Transition component. https://splidejs.com/transition/
And here are the built-in Fade component and CSS for the fade transition. Both are very simple and easy to customize. https://github.com/Splidejs/splide/blob/master/src/js/transitions/fade/index.js https://github.com/Splidejs/splide/blob/master/src/sass/core/object/modifiers/_fade.scss
Hello, I just write some code and it works. I think it is better implementation, but is up to you. New JS code below comments
//CSS part
.splide__list {
margin: 0!important;
padding: 0!important;
height: 100%;
display: flex;
width: -webkit-max-content;
width:max-content;
will-change:transform;
}
.splide--fade>.splide__track>.splide__list {
transform: translate3d(0px,0,0);
width: 100%;
will-change: inherit;
}
.splide--fade>.splide__track>.splide__list>.splide__slide {
pointer-events: none;
width: 100%;
}
html.no-js .splide--fade>.splide__track>.splide__list>.splide__slide,
.splide--fade>.splide__track>.splide__list>.splide__slide.is-active {
pointer-events: auto;
}
.splide__list>.splide__slide:first-child {
z-index: 2;
}
I had to use
type: "fade"
otherwise if declare
type:"fade-2"
it not work, because on splide__list is some translateX. I dont know, where is it taken.
new code with resize event
slider.mount({}, function(Splide, Components) {
return {
mount: function mount() {
// sometimes on "mount" it trigger also "resize" event, sometimes dont, so we have to do apply translate3d twice
Splide.on('resize', function() {
Array.prototype.forEach.call( Components.Elements.slides, function(slide, i) {
slide.style.transform = `translate3d(-`+ Components.Elements.list.clientWidth * i +`px, 0px, 0px)`;
});
});
Array.prototype.forEach.call( Components.Elements.slides, function(slide, i) {
slide.style.opacity = ( Splide.index >= i ) ? `1` : `0`;¨
slide.style.transform = `translate3d(-`+ Components.Elements.list.clientWidth * i +`px, 0px, 0px)`;
if( Splide.index === i )
slide.style.zIndex = 2;
});
},
start( destIndex, newIndex, prevIndex, coord, done ) {
setTimeout(function() {
done();
})
Array.prototype.forEach.call( Components.Elements.slides, function(slide, i) {
slide.style.transition = `opacity ${ Splide.options.speed }ms ease 0s`;
slide.style.opacity = ( newIndex >= i ) ? `1` : `0`;
slide.style.zIndex = 'inherit';
});
}
}
} );
I just realized, that Splide.on ( mounted resize updated refresh ) is not necessary. It just works with resize event so new code updated.
Hey 1ucay, I was having this same issue, so I'm very glad you're addressing it!
Would you by chance know how to implement your new code with the React Splide?
Hi @robbybuckets , sorry, I dont know anything about React.
All good! Thanks anyways!
Close the issue due to the major version update. Feel free to create a new issue or open a new discussion.
The solution by @1ucay is nice, but there’s still a possibly unwanted fade effect when navigating from last to first slide.