티스토리 뷰

Youtube 따라하기

버튼 호버 효과

트라이에이스 2020. 12. 11. 10:30

<!DOCTYPE HTML>
<html lang="ko">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>버튼 호버 효과</title>
<style>
* { margin:0; padding:0; box-sizing: border-box;}
body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  flex-direction: column;
  background: #111;
}
.btn {
  position: relative;
  padding: 15px 40px;
  border: 2px solid #41f321;
  margin: 10px;
  display: inline-block;
  text-decoration: none;
  color: #41f321;
  letter-spacing: 2px;
  text-transform: uppercase;
  overflow: hidden;
  transition: 0.5s;
}
.btn:hover {
  color: #111;
}
.btn span {
  position: absolute;
  display: block;
  width: 0;
  height: 0;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #41f321;
  transition: width 0.5s, height 0.5s;
  z-index: -1;
}
.btn:hover span {
  width: 350px;
  height: 350px;
}
</style>
</head>

<body>
  <a href="#" class="btn"><span></span>Button</a>
  <a href="#" class="btn"><span></span>Button</a>

  <script src="http://code.jquery.com/jquery-latest.js"></script>
  <script>
    $(document).ready(function(e) {
      $('.btn').on('mouseenter', function(e) {
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;
        $(this).find('span').css({top:y,left:x});
      });
      $('.btn').on('mouseout', function(e) {
        x = e.pageX - $(this).offset().left;
        y = e.pageY - $(this).offset().top;
        $(this).find('span').css({top:y,left:x});
      });
    })
  </script>
</body>
</html>

출처: www.youtube.com/watch?v=4DkMKyWJlvk&ab_channel=OnlineTutorials

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함