splide icon indicating copy to clipboard operation
splide copied to clipboard

better fade effect without white background / z-index problem with fast click over navigation

Open 1ucay opened this issue 6 years ago • 10 comments

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

1ucay avatar Nov 17 '20 23:11 1ucay

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

NaotoshiFujita avatar Nov 18 '20 06:11 NaotoshiFujita

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;
}

1ucay avatar Nov 18 '20 09:11 1ucay

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.

1ucay avatar Nov 18 '20 09:11 1ucay

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';
			});

		}
	}
} );

1ucay avatar Nov 18 '20 10:11 1ucay

I just realized, that Splide.on ( mounted resize updated refresh ) is not necessary. It just works with resize event so new code updated.

1ucay avatar Nov 20 '20 08:11 1ucay

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?

robbybuckets avatar Nov 22 '20 21:11 robbybuckets

Hi @robbybuckets , sorry, I dont know anything about React.

1ucay avatar Nov 23 '20 13:11 1ucay

All good! Thanks anyways!

robbybuckets avatar Nov 23 '20 20:11 robbybuckets

Close the issue due to the major version update. Feel free to create a new issue or open a new discussion.

NaotoshiFujita avatar Oct 09 '21 14:10 NaotoshiFujita

The solution by @1ucay is nice, but there’s still a possibly unwanted fade effect when navigating from last to first slide.

hyvyys avatar May 06 '24 13:05 hyvyys