[JS] Transition Event

Chenยท2024๋…„ 6์›” 12์ผ
0

Javascript

๋ชฉ๋ก ๋ณด๊ธฐ
13/22
post-thumbnail

์™œ ๋ณผ์˜ ์œ„์น˜๊ฐ€ e.client ๊ฐ’๊ณผ ๋‹ค๋ฅผ๊นŒ?!

ํด๋ฆญ์‹œ e.clientX, e.clientY๊ฐ’์„ ๋”ฐ๋ผ์˜ค๋„๋ก ํ–ˆ์Œ. ๊ทธ์น˜๋งŒ ๋งˆ์šฐ์Šค๋ณด๋‹ค ์กฐ๊ธˆ ๋” bottom + right์— ์žˆ์Œ.

๋งˆ์ง„์ด ์žˆ๊ธฐ ๋•Œ๋ฌธ...reset.css๋กœ ๋งˆ์ง„ ์•ˆ ์ง€์›Œ์„œ

ํ•ด๊ฒฐ๋ฐฉ์‹ 2. position absolute

๋˜, ๋งˆ์šฐ์Šค ์ปค์„œ๋ฅผ ์„ผํ„ฐ์— ์œ„์น˜์‹œํ‚ค๋ ค๋ฉด -15px์”ฉ ํ•ด์ค˜์•ผ ๋จ

.ball {
    position: absolute;
    left: 0;
    top: 0;
    margin: -15px 0 0 -15px;
}

๋˜๋Š”

window.addEventListener('click', function (e) {
    ballElm.style.transform = `translate(${e.clientX - 15}px, ${e.clientY - 15}px)`;
});


transitionend ์ด๋ฒคํŠธ

ํŠธ๋žœ์ง€์…˜ ๋๋‚ฌ์„ ๋•Œ

e.elapsedTime

transition์ด ์žฌ์ƒ๋˜๋Š”๋ฐ ์–ผ๋งˆ๋‚˜ ์‹œ๊ฐ„์ด ๊ฒฝ๊ณผํ–ˆ๋ƒ

์ฆ‰, transition-duration ์†์„ฑ๊ฐ’์ด ๋‚˜์˜ด

e.propertyName

ballElm.addEventListener('transitionend', function (e) {
    ballElm.classList.add('end');
    console.log(e.elapsedTime); // 2, 2
    console.log(e.propertyName); // transform, bg-color
});


transitionstart ์ด๋ฒคํŠธ

ballElm.addEventListener('transitionstart', function (e) {
    ballElm.classList.add('end');
    console.log(e.elapsedTime); // 0, 0
    console.log(e.propertyName); // transform, bg-color
});

profile
ํ˜„์‹ค์ ์ธ ๋ชฝ์ƒ๊ฐ€

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