logo

Slider responsive

Script à placer dans le head pour que les animations fonctionnent :

<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>

JavaScript à placer avant la fermeture du body :

<script>AOS.init({});</script>

jQuery

$(function(){
        $('.carousel-item').eq(0).addClass('active');
        var total = $('.carousel-item').length;
        var current = 0;
        $('#moveRight').on('click', function(){
            var next=current;
            current= current+1;
            setSlide(next, current);
        });
        $('#moveLeft').on('click', function(){
            var prev=current;
            current = current- 1;
            setSlide(prev, current);
        });
        function setSlide(prev, next){
            var slide= current;
            if(next>total-1){
                slide=0;
                current=0;
            }
            if(next<0){
                slide=total - 1;
                current=total - 1;
            }
            $('.carousel-item').eq(prev).removeClass('active');
            $('.carousel-item').eq(slide).addClass('active');
            setTimeout(function(){

            },800);
        }
    });

Html

<div class="carousel main">
    <div class="carousel__nav">
     <span id="moveLeft" class="carousel__arrow">
          <svg class="carousel__icon" width="24" height="24" viewBox="0 0 24 24">
      <path d="M20,11V13H8L13.5,18.5L12.08,19.92L4.16,12L12.08,4.08L13.5,5.5L8,11H20Z"></path>
  </svg>
      </span>
        <span id="moveRight" class="carousel__arrow" >
        <svg class="carousel__icon"  width="24" height="24" viewBox="0 0 24 24">
    <path d="M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"></path>
  </svg>
      </span>
    </div>
    <div class="carousel-item carousel-item--1">
        <div class="carousel-item__image"></div>
        <div class="carousel-item__info" data-aos="fade-right">
            <div class="carousel-item__container">
                <h2 class="carousel-item__subtitle">The grand moment </h2>
                <h1 class="carousel-item__title">Le tour</h1>
                <p class="carousel-item__description">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
                <a href="#" class="carousel-item__btn">Explore the tour</a>
            </div>
        </div>
    </div>
    <div class="carousel-item carousel-item--2">
        <div class="carousel-item__image"></div>
        <div class="carousel-item__info" data-aos="fade-right">
            <div class="carousel-item__container">
                <h2 class="carousel-item__subtitle">The big window </h2>
                <h1 class="carousel-item__title">Minimal window</h1>
                <p class="carousel-item__description">Clear Glass Window With Brown and White Wooden Frame iste natus error sit voluptatem accusantium doloremque laudantium.</p>
                <a href="#" class="carousel-item__btn">Read the article</a>
            </div>
        </div>
    </div>
    <div class="carousel-item carousel-item--3">
        <div class="carousel-item__image"></div>
        <div class="carousel-item__info" data-aos="fade-right">
            <div class="carousel-item__container">
                <h2 class="carousel-item__subtitle">Tropical palms </h2>
                <h1 class="carousel-item__title">Palms</h1>
                <p class="carousel-item__description">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
                <a href="#" class="carousel-item__btn">Explore the palms</a>
            </div>
        </div>
    </div>

    <div class="carousel-item carousel-item--4">
        <div class="carousel-item__image"></div>
        <div class="carousel-item__info" data-aos="fade-right">
            <div class="carousel-item__container">
                <h2 class="carousel-item__subtitle">Beach </h2>
                <h1 class="carousel-item__title">The beach </h1>
                <p class="carousel-item__description">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
                <a href="#" class="carousel-item__btn">Explore the beach</a>
            </div>
        </div>
    </div>

    <div class="carousel-item carousel-item--5">
        <div class="carousel-item__image"></div>
        <div class="carousel-item__info" data-aos="fade-right">
            <div class="carousel-item__container">
                <h2 class="carousel-item__subtitle">The white building </h2>
                <h1 class="carousel-item__title">White building</h1>
                <p class="carousel-item__description">Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam.</p>
                <a href="#" class="carousel-item__btn">Read the article</a>
            </div>
        </div>
    </div>
</div>

CSS

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    display: flex;
    display: -webkit-flex;
    justify-content: center;
    -webkit-justify-content: center;
    align-items: center;
    -webkit-align-items: center;
}

body {
    background-color: #eaeaea;
}

.carousel.main {
    padding: 0 0 0 50px;
}

.carousel {
    width: 100%;
    height: 100%;
    display: flex;
    max-width: 900px;
    max-height: 550px;
    overflow: hidden;
    position: relative;
}

.carousel-item {
    visibility:visible;
    display: flex;
    width: 100%;
    height: 100%;
    align-items: center;
    justify-content: flex-end;
    -webkit-align-items: center;
    -webkit-justify-content: flex-end;
    position: relative;
    background-color: #fff;
    flex-shrink: 0;
    -webkit-flex-shrink: 0;
    position: absolute;
    z-index: 0;
    /* transition: 1s all ease-out; */
}

.carousel-item__info {
    height: 60%;
    display: flex;
    justify-content: center;
    flex-direction: column;
    display: -webkit-flex;
    -webkit-justify-content: center;
    -webkit-flex-direction: column;
    order: 1;
    left: -50px;
    margin: auto;
    padding: 0 40px;
    width: 40%;
    position: absolute;
    background: #fff;
}

.carousel-item__image {
    width: 100%;
    height: 100%;
    order: 2;
    align-self: flex-end;
    flex-basis: 100%;
    -webkit-order: 2;
    -webkit-align-self: flex-end;
    -webkit-flex-basis: 100%;
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
    position:relative;
    /* transform: translateX(100%); */
    /* transition: 1s all ease-in-out; */
}

.carousel-item__subtitle {
    font-family: 'Open Sans', sans-serif;
    letter-spacing: 3px;
    font-size: 10px;
    text-transform: uppercase;
    margin: 0;
    color: #7E7E7E;
    font-weight: 700;
    /* transform: translateY(25%); */
    opacity: 0;
    visibility: hidden;
    /* transition: 1s all ease-in-out; */
}

.carousel-item__title {
    margin: 15px 0 0 0;
    font-family: 'Playfair Display', serif;
    font-size: 44px;
    line-height: 45px;
    letter-spacing: 3px;
    font-weight: 700;
    color: #2C2C2C;
    transform: translateY(25%);
    opacity: 0;
    visibility: hidden;
    transition: 1s all ease-in-out;
}

.carousel-item__description {
    /* transform: translateY(25%); */
    opacity: 0;
    visibility: hidden;
    transition: 1s all ease-out;
    margin-top: 35px;
    font-family: 'Open Sans', sans-serif;
    font-size: 13px;
    color: #7e7e7e;
    line-height: 22px;
    margin-bottom: 35px;
}

.carousel-item--1 .carousel-item__image{
    background-image: url('https://images.pexels.com/photos/991012/pexels-photo-991012.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940');
}


.carousel-item--2 .carousel-item__image{
    background-image: url('https://images.pexels.com/photos/921294/pexels-photo-921294.png?auto=compress&cs=tinysrgb&h=750&w=1260');
}

.carousel-item--3 .carousel-item__image{
    background-image: url('https://images.pexels.com/photos/92733/pexels-photo-92733.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260');
}

.carousel-item--4 .carousel-item__image{
    background-image: url('https://images.pexels.com/photos/1008732/pexels-photo-1008732.jpeg?auto=compress&cs=tinysrgb&h=750&w=1260');
}

.carousel-item--5 .carousel-item__image{
    background-image: url('https://images.pexels.com/photos/1029614/pexels-photo-1029614.jpeg?auto=compress&cs=tinysrgb&dpr=2&h=650&w=940');
}

.carousel-item__container{

}

.carousel-item__btn {
    width: 35%;
    color: #2C2C2C;
    font-family: 'Open Sans', sans-serif;
    letter-spacing: 3px;
    font-size: 11px;
    text-transform: uppercase;
    margin: 0;
    width: 35%;
    font-weight: 700;
    text-decoration: none;
    /* transform: translateY(25%); */
    opacity: 0;
    visibility: hidden;
    /* transition: 1s all ease-in-out; */
}

.carousel__nav {
    position: absolute;
    right: 10px;
    z-index: 2;
    background-color: #fff;
    bottom: 10px;
}

.carousel__icon {
    display: inline-block;
    vertical-align: middle;
    width: 16px;
    fill: #5d5d5d;
}

.carousel__arrow {
    cursor: pointer;
    display: inline-block;
    padding: 11px 15px;
    position: relative;
}

.carousel__arrow:nth-child(1):after {
    content:'';
    right: -3px;
    position: absolute;
    width: 1px;
    background-color: #b0b0b0;
    height: 14px;
    top: 50%;
    margin-top: -7px;
}

.active{
    z-index: 1;
    display: flex;
    visibility:visible;
}

.active .carousel-item__subtitle, .active .carousel-item__title, .active .carousel-item__description,.active .carousel-item__btn{
    transform: translateY(0);
    opacity: 1;
    transition: 1s all ease-in-out;
    visibility: visible;
}

.active .carousel-item__image{
    transition: 1s all ease-in-out;
    transform: translateX(0);
}

@media (max-width: 425px) {
    .carousel.main {
        padding: 0;
        margin: 0;
    }
    .carousel-item {
        flex-direction: column-reverse;
    }
    .carousel-item__info {
        position: initial;
        padding: 1rem;
        width: auto;
        height: auto;
    }
}

[data-aos] {
    pointer-events: none
}

[data-aos].aos-animate {
    pointer-events: auto
}

[data-aos][data-aos][data-aos-duration="400"],
body[data-aos-duration="400"] [data-aos] {
    transition-duration: 1s
}

[data-aos][data-aos][data-aos-easing=ease],
body[data-aos-easing=ease] [data-aos] {
    transition-timing-function: ease
}

@media screen {
    html:not(.no-js) [data-aos=fade-right] {
        -webkit-transform: translate3d(-100px, 0, 0);
        transform: translate3d(-100px, 0, 0)
    }

    html:not(.no-js) [data-aos^=fade][data-aos^=fade] {
        opacity: 0;
        transition-property: opacity, -webkit-transform;
        transition-property: opacity, transform;
        transition-property: opacity, transform, -webkit-transform
    }

    html:not(.no-js) [data-aos^=fade][data-aos^=fade].aos-animate {
        opacity: 1;
        -webkit-transform: none;
        transform: none
    }
}

Une idée ? Partagez-la !

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *