프론트엔드/컴포넌트

돋보기 효과

syleemomo 2024. 2. 14. 22:10
728x90

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <div class="bg"></div>
  <div class="circle"></div>
  <script>
    const bg = document.querySelector('.bg')
    const circle = document.querySelector('.circle')
    bg.addEventListener('mousemove', function(e){
      console.log(e.pageX, e.pageY)
      circle.style.left = `${e.pageX}px`
      circle.style.top = `${e.pageY}px`
    })
  </script>
</body>
</html>
body{
  margin: 0;
}
.bg{
  width: 100%;
  height: 100vh;
  background-image: url(bg.png);
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
.circle{
  width: 300px; height: 300px;
  border-radius: 50%;
  background-color: gray;
  position: absolute;
  transform: translate(-50%, -50%);
  border: 3px solid #333;
  mix-blend-mode: multiply;
  cursor: zoom-in;
  filter: blur(10px);
}
.gray{
  filter: grayscale(50%);
}
728x90