Devlog/Web

[React] hover effect ์ด๋ฒคํŠธํ•จ์ˆ˜๊ฐ€ child element์— ์ œ๋Œ€๋กœ ์ ์šฉ์ด ์•ˆ ๋  ๋•Œ ํ•ด๊ฒฐ๋ฐฉ๋ฒ•

FATKITTY 2021. 10. 11. 18:53
๋ฐ˜์‘ํ˜•

๐Ÿ’ข onMouseOver ์ด๋ฒคํŠธ๊ฐ€ child element์—๋Š” ์ ์šฉ ์•ˆ ๋˜๊ณ  parent element์—๋งŒ ์ ์šฉ๋  ๋•Œ

 

โ–ช์—๋Ÿฌ๋‚ด์šฉ :

๋งˆ์šฐ์Šค ์ปค์„œ๋ฅผ ๋ฉ”๋‰ด๋ฒ„ํŠผ ์œ„์— ์˜ฌ๋ ธ์„ ๋•Œ ๋ฒ„ํŠผ์ด ํšŒ์ƒ‰์œผ๋กœ ๋ฐ”๋€Œ๊ณ , ์ปค์„œ๋ฅผ ๋–ผ๋ฉด ์›๋ž˜ ์ƒ‰์œผ๋กœ ๋Œ์•„์˜ค๋„๋ก ์ด๋ฒคํŠธํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค. ์ž˜ ์ž‘๋™ํ•˜๋Š” ๋“ฏ ํ–ˆ๋Š”๋ฐ, ์ž์„ธํžˆ ๋ณด๋‹ˆ๊นŒ ๋ฉ”๋‰ด๋ฒ„ํŠผ์— ์œ„์น˜ํ•œ svg ์•„์ด์ฝ˜ ์œ„์— ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ฆฌ๋ฉด ์ƒ‰์ด ์ œ๋Œ€๋กœ ์•ˆ ๋ฐ”๋€Œ๋Š” ํ˜„์ƒ์ด ๋ฐœ์ƒํ–ˆ๋‹ค.

๋ฉ”๋‰ด component ์•ˆ์— child๋กœ ์•„์ด์ฝ˜์„ ๋„ฃ์–ด๋†จ์œผ๋‹ˆ๊นŒ, child element์—๋Š” parent์— ์ ์šฉ๋œ ์ด๋ฒคํŠธํ•จ์ˆ˜๊ฐ€ ์ œ๋Œ€๋กœ ์ ์šฉ์ด ์•ˆ ๋˜๋Š” ๋ฌธ์ œ๋ผ๊ณ  ์ƒ๊ฐํ•˜๊ณ  ํ•ด๊ฒฐ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ดค๋‹ค.

์ž˜ ๋˜๋Š” ๋“ฏ ํ–ˆ์œผ๋‚˜... ์•„์ด์ฝ˜ ์œ„์— ์ปค์„œ๋ฅผ ์˜ฌ๋ฆฌ๋‹ˆ ์˜ˆ์ƒ์น˜ ๋ชป ํ•œ ํ˜„์ƒ ๋ฐœ์ƒ

 

โ–ช์›์ธ : e.target ์‚ฌ์šฉ

 

โ–ชํ•ด๊ฒฐ๋ฐฉ๋ฒ•: e.currentTarget ์‚ฌ์šฉ

function MouseOverUserMenu(e) {
  e.currentTarget.style.background = COLOR.whisperGray;
}

function MouseOutUserMenu(e) {
  e.currentTarget.style.background = COLOR.white;
}

 

 

์ฐธ๊ณ ์ž๋ฃŒ

https://stackoverflow.com/questions/38316442/reactjs-mouseout-firing-on-hover-of-child-element

๋ฐ˜์‘ํ˜•