-
Notifications
You must be signed in to change notification settings - Fork 0
/
menu-closebtn2.html
64 lines (47 loc) · 1.58 KB
/
menu-closebtn2.html
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!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>
</head>
<body>
<style>
*{margin: 0; padding: 0;}
ul{list-style: none;}
a{text-decoration: none; color:inherit;}
.btn-menu{ width: 50px; height: 50px; display: block; background: #f00;}
.btn-close{width: 50px; height: 50px; display: block; background: #00f;}
.menu{
position: fixed;
top: 0; left: -100%;
width: 100%;
height: 100%;
background: #ccc;
transition: left 0.5s; /* 0.5초로 왔다갔다 이동 -> 반동을 준다 */
}
.menu.active{
left: 0;
}
</style>
<a href="" class="btn-menu">메뉴</a>
<div class="menu">
<a href="" class="btn-close">닫기</a>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
//addClass, removeClass를 사용해서 버튼 여닫기
$(function(){
$('.btn-menu').click(function(e){
e.preventDefault();
$('.menu').addClass('active') //active라는 클래스 값 추가
})
$('.btn-close').click(function(e){
e.preventDefault();
$('.menu').removeClass('active') //클래스 삭제해서, left가 0->-100이 되도록
})
})
</script>
</body>
</html>