slides carousel with parallex effect the work on scroll

Viewed 65

I am trying to make a carousel that change slides on scroll, every slide contains 4 layers (background, flower , and a shape) what i want is on scroll the carousel change to the next slide but every layers should slides in efferent timing , exactly like this demo

here is a screenshot of the carousel section

i have create the carousel and its working on scroll, but i don't know how to make efferent layers and animate their slide effect like the link above.

my code:-

    <div id="sec-4" class="section">
        <div class="carousel">
            <div>
              <div class="question">
                <div class="avatar">
                  <img width="150" height="150" src="https://i.pravatar.cc/300" class=" rounded-circle " alt=""> </div>
                <div class="message">1 Lorem ipsum dolor sit amet consectetur adipisicing elit. Labore doloribus, </div>
              </div>
          
            </div>
            <div>
              <div class="question">
                <div class="avatar">
                  <img width="150" height="150" src="https://i.pravatar.cc/300" class="rounded-circle " alt=""> </div>
                <div class="message">2 Lorem ipsum dolor sit amet consectetur adipisicing elit. Labore doloribus, </div>
              </div>
            
            
            </div>
            <div>
              <div class="question">
                <div class="avatar">
                  <img width="150" height="150" src="https://i.pravatar.cc/300" class=" rounded-circle " alt=""> </div>
                <div class="message">3 Lorem ipsum dolor sit amet consectetur adipisicing elit. Labore doloribus, </div>
              </div>
            
            
            </div>
          </div>
    </div>


#sec-4{
    height: 100vh;
    font-size: 3rem;
    padding: 0%;
    display: flex;
    justify-content: center;
    align-content: center;
 
    
}
 #sec-4::before{
     content: "";
     position: absolute;
     width: 100%;
     height: 100vh;
     background-color: firebrick;
  
 }
 .rounded-circle{
     border-radius: 50%;
 }
.carousel{
    background-color: firebrick;
    height: 500px;
    width: 80%;
    
}
.message{
    width: 50%;
    position: relative;
    left: 30%;
    color: white;

}
.question{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 400px;
}



 
$(document).ready(function(){
  
  $('.carousel').slick({
     dots: true,
     slidesToShow: 1,
     slidesToScroll: 1,
     infinite: true,
     arrows: true,
     adaptiveHeight: true,
 });

 var $questionAvatar = $('.question .avatar');
 var $questionMessagge = $('.question .message');


 var tlQuestions = new TimelineMax({paused: true, delay: 0.4});

 TweenMax.set($questionAvatar, {autoAlpha: 0, scale: 0.6})
 TweenMax.set($questionMessagge, {autoAlpha: 0, scale: 0.6})

  tlQuestions
  .set($questionAvatar, {autoAlpha: 0, scale: 0.6})
  .set($questionMessagge, {autoAlpha: 0, scale: 0.6})
  .to($questionAvatar, 1, {autoAlpha: 1, scale: 1, ease: Back.easeOut.config(1)})
  .to($questionMessagge, 1, {autoAlpha: 1, scale: 1, ease: Back.easeOut.config(1), transformOrigin: 'bottom bottom'}, '+=0.1')

 tlQuestions.play();

 $('.carousel').on('afterChange', function(event, slick, currentSlide, nextSlide){
     // var currentSlide = $(slick.$slides.get(currentSlide));
   tlQuestions.play();
 });  

 $('.carousel').on('beforeChange', function(event, slick, currentSlide, nextSlide){
   tlQuestions.restart();
 });




$('.carousel').on('wheel', (function(e) {
e.preventDefault();
clearTimeout(scroll);
scroll = setTimeout(function(){scrollCount=0;}, 200);
if(scrollCount) return 0;
scrollCount=1;

if (e.originalEvent.deltaY < 0) {
 $(this).slick('slickPrev');
} else {
 $(this).slick('slickNext');
}
})); 
});

my pen:- Codepen

1 Answers

I have tried to use Swiper.js, Slick and all the possible sliders. but the main problem was that there was 4 layers and the top layer was covering the Swiper so it wont work because its covered. Then I solved this issue by GSAP scroll Trigger which I triggered the layers moments by mouse scrolling without the need to use any carousel plugin.

Related