[miniProjects] 20_Button Ripple Effect

๋ณด๋ฆฌยท2023๋…„ 6์›” 16์ผ
0

miniProjects

๋ชฉ๋ก ๋ณด๊ธฐ
21/47

20_Button Ripple Effect

๐Ÿ’ป ์ฃผ์ œ : ๋ฒ„ํŠผ ํด๋ฆญ์‹œ ๋งˆ์šฐ์Šค ํฌ์ธํ„ฐ์— ํŒŒ๊ธ‰ ํšจ๊ณผ๋ฅผ ์คŒ.

 // ํด๋ฆญํ•œ ๊ณณ์˜ ์ขŒํ‘œ
    const x = e.clientX;
    const y = e.clientY;

    // ๋ฒ„ํŠผ ๋‚ด์—์„œ๋งŒ ์ ์šฉ๋˜์–ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ฒ„ํŠผ์˜ ์œ„์น˜๋ฅผ ์ ์šฉํ•จ.
    const buttonTop = e.target.offsetTop;
    const buttonLeft = e.target.offsetLeft;

    // ๋ฒ„ํŠผ ๋‚ด์—์„œ ํด๋ฆญํ–ˆ์„ ๋–„ ์ขŒํ‘œ
    const xInside = x - buttonLeft;
    const yInside = y - buttonTop;

    const circle = document.createElement('span');
    circle.classList.add('circle');
    circle.style.top = yInside + 'px';
    circle.style.left = xInside + 'px';

    // this๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ํ™”์‚ดํ‘œ ํ•จ์ˆ˜๊ฐ€ ์•„๋‹Œ ์ผ๋ฐ˜ ํ•จ์ˆ˜ ํ˜•ํƒœ๋กœ ์จ์•ผ ํ•จ.
    this.appendChild(circle);
profile
์ •์‹ ์ฐจ๋ ค ์ด ๊ฐ๋ฐ•ํ•œ ์„ธ์ƒ์†์—์„œ

0๊ฐœ์˜ ๋Œ“๊ธ€