๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ดํŽ™ํŠธ

03. ์Šฌ๋ผ์ด๋“œ ์ดํŽ™ํŠธ - ์ขŒ๋กœ ์›€์ง์ด๊ธฐ

by Youcodein 2022. 8. 29.
728x90
๋ฐ˜์‘ํ˜•

์Šฌ๋ผ์ด๋“œ ์ดํŽ™ํŠธ 02. ์ขŒ๋กœ ์›€์ง์ด๊ธฐ

javascript๋ฅผ ์ด์šฉํ•˜์—ฌ ์Šฌ๋ผ์ด๋“œ ์ดํŽ™ํŠธ๋ฅผ ๋งŒ๋“ค์—ˆ์Šต๋‹ˆ๋‹ค. ์—ด์‹ฌํžˆ ๊ณต๋ถ€ํ•˜์„ธ์š”!


์Šฌ๋ผ์ด๋“œ ์ดํŽ™ํŠธ 02

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

 const sliderInner = document.querySelector(".slider__inner");   //์›€์ง์ด๋Š” ์˜์—ญ
const slider = document.querySelectorAll(".slider");               //์ด๋ฏธ์ง€
let currentIndex = 0;

sliderInner.style.transition = "all 0.6s";

setInterval(() => {

    currentIndex = (currentIndex + 1) % slider.length;
    sliderInner.style.transform = "translateX("+ -800 * currentIndex + "px)";
}, 2000);

GSAP

const slider = document.querySelectorAll(".slider");
let currentIndex = 0;

setInterval(() => {
    currentIndex = (currentIndex + 1) % slider.length;

    gsap.to(".slider__inner",{
        duration : 0.6,
        x : -800 * currentIndex,
    });

}, 2000);

JQuery

let currentIndex = 0;
setInterval(() => {
    currentIndex = (currentIndex +1) % $(".slider").length;
    // sliderInner.style.transition = "all 0.6s"
    // $(".slider__inner").css(
    //     "transform", "translateX("+ -800 * currentIndex +"px)"
    // );
    $(".slider__inner").css("position", "relative");
    $(".slider__inner").animate({left : -800 * currentIndex},600)
}, 2000);
728x90
๋ฐ˜์‘ํ˜•

๋Œ“๊ธ€