[miniProjects] 36_Hoverboard

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

miniProjects

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

36_Hoverboard

๐Ÿ’ป์ฃผ์ œ : ๋ฐ•์Šค์— ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ ค๋†“์œผ๋ฉด ๋žœ๋ค ์ƒ‰์ด ์น ํ•ด์ง.

โœจJS

const container = document.getElementById('container')
const colors = ['#FFACAC', '#40128B', '#79E0EE', '#FFEA20', '#82CD47']
const SQUARES = 500

for(let i = 0; i < SQUARES; i++) {
  const sqaure = document.createElement('div')
  sqaure.classList.add('square')

  sqaure.addEventListener('mouseover', () => setColor(sqaure))
  sqaure.addEventListener('mouseout', () => removeColor(sqaure))

  container.appendChild(sqaure)
}

function setColor(element) {
  const color = getRandomColor()
  element.style.background = color
  element.style.boxShadow = `0 0 2px ${color}, 0 0 10px ${color}`
}

function removeColor(element) {
  element.style.background = '#1d1d1d'
  element.style.boxShadow = '0 0 2px #000'
}

function getRandomColor() {
  return colors[Math.floor(Math.random() * colors.length)]
}

โœจCSS

.square {
  background-color: #1d1d1d;
  box-shadow: 0 0 2px #000;
  width: 16px;
  height: 16px;
  margin: 2px;
  /* 2์ดˆ ์ง€๋‚˜๋ฉด ์ƒ‰์ด ์‚ฌ๋ผ์ง */
  transition: 2s ease;
}

.square:hover {
  /* ๋งˆ์šฐ์Šค๋ฅผ ์˜ฌ๋ ธ์„ ๋•Œ ๋ฐ”๋กœ ์ƒ‰์ด ๋‚˜ํƒ€๋‚˜๋„๋ก */
  transition-duration: 0s;
}
profile
์ •์‹ ์ฐจ๋ ค ์ด ๊ฐ๋ฐ•ํ•œ ์„ธ์ƒ์†์—์„œ

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