⟨/⟩
SnipBox
← Voltar ao catálogo
Catálogo
›
JavaScript
›
Swiper Js Carousel with progress animations
Swiper Js Carousel with progress animations
JavaScript
HTML
CSS
JS
Link base: https://codepen.io/TimGuignard/pen/WbGzRvE
📅 06/04/2026
👁 11 visualizações
SwipperJS
Visualização ao Vivo
🔄 Recarregar
HTML
📋 Copiar
<div class="co-carousel-wrap"> <div class="swiper co-carousel"> <!-- Additional required wrapper --> <div class="swiper-wrapper"> <!-- Slides --> <div class="swiper-slide co-carousel__slide"> <div class="co-card"> <div class="co-card__shoe"> <img class="co-card__shoe-img" src="https://codocular.com/lab/swiper-carousel/nike1.85b9a747.png" alt="" /> <span class="co-card__shoe-shadow"></span> </div> <div class="co-card__info"> <div class="co-card__collection text-mask"> <span>Men's Original</span> </div> <div class="co-card__title text-mask"> <span>Nike Air Force</span> </div> <div class="co-card__price text-mask"><span>$150.00</span></div> </div> </div> </div> <div class="swiper-slide co-carousel__slide"> <div class="co-card co-card--style-1"> <div class="co-card__shoe"> <img class="co-card__shoe-img" src="https://codocular.com/lab/swiper-carousel/nike2.3412fa36.png" alt="" /> <span class="co-card__shoe-shadow"></span> </div> <div class="co-card__info"> <div class="co-card__collection text-mask"> <span>Jordans</span> </div> <div class="co-card__title text-mask"> <span>Nike Air Jordan</span> </div> <div class="co-card__price text-mask"><span>$249.99</span></div> </div> </div> </div> <div class="swiper-slide co-carousel__slide"> <div class="co-card co-card--style-2"> <div class="co-card__shoe"> <img class="co-card__shoe-img" src="https://codocular.com/lab/swiper-carousel/nike3.14907490.png" alt="" /> <span class="co-card__shoe-shadow"></span> </div> <div class="co-card__info"> <div class="co-card__collection text-mask"> <span>Purple Rain</span> </div> <div class="co-card__title text-mask"> <span>Nike Air Max</span> </div> <div class="co-card__price text-mask"><span>$150.00</span></div> </div> </div> </div> <div class="swiper-slide co-carousel__slide"> <div class="co-card co-card--style-3"> <div class="co-card__shoe"> <img class="co-card__shoe-img" src="https://codocular.com/lab/swiper-carousel/nike4.62fca82d.png" alt="" /> <span class="co-card__shoe-shadow"></span> </div> <div class="co-card__info"> <div class="co-card__collection text-mask"> <span>Men's Original</span> </div> <div class="co-card__title text-mask"> <span>Nike Air Force</span> </div> <div class="co-card__price text-mask"><span>$150.00</span></div> </div> </div> </div> </div> </div> <div class="co-carousel__nav-buttons"> <div class="co-carousel__nav-button prev"> <span>Prev</span> </div> <div class="co-carousel__nav-button next"> <span>Next</span> </div> </div> </div> <footer class="footer"> <div class="footer-links"> <a href="https://x.com/TimGuignard" target="_blank" class="co-btn co-btn--link" >X</a > <a href="https://codepen.io/TimGuignard/" target="_blank" class="co-btn co-btn--link" >Codepen</a > <a href="https://dribbble.com/TimGuignard" target="_blank" class="co-btn co-btn--link" >Dribbble</a > <a href="https://codocular.com/" target="_blank" class="co-btn co-btn--link" >Codocular</a > <a href="https://github.com/TimGuignard/swiper-carousel" target="_blank" class="co-btn co-btn--link">Github</a> </div> </footer> <div class="co-background co-background--style-0"></div> <div class="co-background co-background--style-1"></div> <div class="co-background co-background--style-2"></div> <div class="co-background co-background--style-3"></div>
CSS
📋 Copiar
:root { /* theme variable */ --codocular-color-hex: #e34c26; --codocular-color: 227, 76, 38; --background-color: #000; --main-font-color: #000; } $prefix: co; * { box-sizing: border-box; } html { height: 100%; -moz-font-smoothing: antialiased; -webkit-font-smoothing: antialiased; font-smoothing: antialiased; text-rendering: optimizeLegibility !important; font-size: 62.5%; // so 1rem is 10px; } body { height: 100%; margin: 0; margin: 0; font-size: 1.6rem; font-family: "Montserrat", arial, sans-serif; min-height: 100%; display: flex; flex-direction: column; background-color: #fff; color: #000; } .co-btn { cursor: pointer; display: flex; align-items: center; padding: 7px 10px; font-weight: 600; font-size: 10px; text-transform: uppercase; border: 1px solid var(--main-font-color); border-radius: 5px; background: transparent; text-decoration: none; color: var(--main-font-color); transition: 0.3s; box-shadow: 0 0 0px 0px rgba(var(--codocular-color), 0.8); &:hover { box-shadow: 0 0 15px 0px rgba(var(--codocular-color), 0.8); border-color: rgb(var(--codocular-color)); } &:active { transition: 0.1s; box-shadow: 0 0 15px 3px rgba(var(--codocular-color), 0.8); } &--link { border: 0; text-decoration: underline; &:hover { border: 0; box-shadow: none; color: rgb(var(--codocular-color)); } &:after { text-decoration: none; font-weight: 500; content: " ↗"; } } } .footer { z-index: 9; width: 100%; padding: 20px; font-size: 10px; @media (max-width: 768px) { position: static; bottom: auto; left: auto; } &-links { display: flex; justify-content: center; column-gap: 10px; margin-bottom: 10px; } &-copyright { text-align: center; font-size: 12px; a { font-weight: 600; color: rgb(var(--codocular-color)); } } } .#{$prefix}-carousel-wrap{ flex-grow: 1; position: relative; z-index: 9; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; } .#{$prefix}-carousel { margin: 0 auto; width: 50%; height: 400px; overflow: visible; &__slide { display: flex; align-items: center; justify-content: center; } &__nav-buttons { margin-top: 40px; width: 100%; display: flex; justify-content: space-between; } &__nav-button { padding: 10px 0; width: 150px; position: relative; display: flex; flex-direction: column; cursor: pointer; &.prev { align-items: flex-end; } &.next { align-items: flex-start; } &.swiper-button-disabled { opacity: 0.3; } &:hover:not(.swiper-button-disabled) { &.prev { span { transform: translate3d(-10px, 0, 0); } } &.next { span { transform: translate3d(10px, 0, 0); } } } &:before { display: block; content: ""; width: 100%; height: 1px; background-color: #000; } span { font-size: 14px; text-transform: uppercase; padding: 10px 0; transition: cubic-bezier(0.22, 0.74, 0.46, 0.97) 0.3s; } } } .#{$prefix}-card { position: relative; display: flex; align-items: center; justify-content: center; height: 400px; width: 250px; border-radius: 20px; box-shadow: 0 0 3px rgb(0, 0, 0, 0.1); background: rgb(253, 243, 234); background: linear-gradient( 163deg, rgba(253, 243, 234, 1) 0%, rgba(251, 229, 204, 1) 100% ); &--style-1 { background: rgb(247, 253, 252); background: linear-gradient( 163deg, rgba(247, 253, 252, 1) 0%, rgba(195, 227, 221, 1) 100% ); } &--style-2 { background: rgb(252, 244, 244); background: linear-gradient( 163deg, rgba(252, 244, 244, 1) 0%, rgba(246, 200, 203, 1) 100% ); } &--style-3 { background: rgb(249, 242, 251); background: linear-gradient( 163deg, rgba(249, 242, 251, 1) 0%, rgba(234, 199, 245, 1) 100% ); } &__shoe { position: relative; width: 130%; flex-shrink: 0; top: -20px; &-img { user-select: none; position: relative; width: 100%; display: block; z-index: 9; } &-shadow { position: absolute; top: 80px; left: 0; right: 0; margin-left: auto; margin-right: auto; display: block; border-radius: 50%; width: 20px; height: 20px; opacity: 0.3; background-color: rgba(0, 0, 0, 1); box-shadow: 0 0 30px 40px rgba(0, 0, 0, 1); } } &__info { position: absolute; left: 0; right: 0; bottom: 0; padding: 20px; display: table; } &__title { font-weight: 700; font-size: 1.6rem; text-transform: uppercase; } &__collection { font-weight: 600; font-size: 1rem; text-transform: uppercase; opacity: 0.3; } &__price { margin-top: 10px; font-weight: 500; font-size: 1.3rem; } } .text-mask { overflow: hidden; span { display: inline-flex; } } .#{$prefix}-background { top: 0; left: 0; position: fixed; width: 100%; height: 100%; opacity: 0; &--style-0 { background: rgb(253, 243, 234); background: linear-gradient( 163deg, rgba(253, 243, 234, 1) 0%, rgba(251, 229, 204, 1) 100% ); } &--style-1 { background: rgb(247, 253, 252); background: linear-gradient( 163deg, rgba(247, 253, 252, 1) 0%, rgba(195, 227, 221, 1) 100% ); } &--style-2 { background: rgb(252, 244, 244); background: linear-gradient( 163deg, rgba(252, 244, 244, 1) 0%, rgba(246, 200, 203, 1) 100% ); } &--style-3 { background: rgb(249, 242, 251); background: linear-gradient( 163deg, rgba(249, 242, 251, 1) 0%, rgba(234, 199, 245, 1) 100% ); } }
JavaScript
📋 Copiar
import Swiper from 'https://cdn.jsdelivr.net/npm/swiper@12/swiper-bundle.min.mjs'; document.addEventListener("DOMContentLoaded", () => { const backgroundWrapper = document.querySelectorAll(".co-background"); const swiper = new Swiper(".swiper", { loop: false, watchSlidesProgress: true, // allows to use each slide progress: this.slides[i].progress speed: 1000, grabCursor: true, //loopAdditionalSlides: 1, needed if loop is true navigation: { nextEl: ".co-carousel__nav-button.next", prevEl: ".co-carousel__nav-button.prev", }, on: { progress: function (swiper) { swiper.slides.forEach((slide, index) => { const progress = slide.progress; //-1 = right, 1 = left, 0 = middle if (progress >= -1 && progress <= 1) { const rotateShoeMax = 15; const scaleMax = 1.3; const progressPositive = Math.abs(progress); const translateX = progress * -100; const rotateShoe = progressPositive * rotateShoeMax - rotateShoeMax; const rotateCard = progress * -15; const textMaskY = progressPositive * 50; const scale = 1 - progressPositive * 0.2; const opacity = 0.5 - progressPositive * 0.5; // opacity between 0.5 and 0 //slide.querySelector('.co-card').style.transform = `perspective(800px) scale(${scale}) rotateY(${rotateCard}deg) `; slide.querySelector(".co-card").style.transform = `scale(${scale})`; slide.querySelector(".co-card__shoe-img").style.transform = `translate3d(${translateX}px, 0,0) rotate(${rotateShoe}deg)`; slide.querySelector(".co-card__shoe-shadow").style.transform = `translate3d(${translateX / 2}px, 0,0)`; backgroundWrapper[index].style.opacity = opacity.toFixed(2); const textsMask = slide.querySelectorAll(".text-mask span"); textsMask.forEach((t, i) => { t.style.transform = `translate3d(0,${textMaskY * (i + 1)}px,0)`; }); } }); }, setTransition: function (swiper, speed) { swiper.slides.forEach((slide, index) => { slide.querySelector(".co-card").style.transition = `${speed}ms`; slide.querySelector(".co-card__shoe-img").style.transition = `${speed}ms`; slide.querySelector(".co-card__shoe-shadow").style.transition = `${speed}ms`; backgroundWrapper[index].style.transition = `${speed}ms`; const textsMask = slide.querySelectorAll(".text-mask span"); textsMask.forEach((t) => { t.style.transition = `${speed}ms`; }); }); }, }, }); });