반응형
html
<!DOCTYPE html>
<html>
<head>
<title>Parcel Sandbox</title>
<meta charset="UTF-8" />
</head>
<body>
<h1> 안녕하세요</h1>
<p>환영합니다.</p>
<button id="open"> 모달 열기</button>
<div class="modal-wrapper" style="display: none">
<div class="modal">
<div class="modal-title">
안녕하세요
</div>
<p> 모달 내용</p>
<div class="close-wrapper">
<button id="close"> 닫기</button>
</div>
</div>
<script src="src/index.js">
</script>
</body>
</html>
css
body {
font-family: sans-serif;
}
.modal-wrapper {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
}
.modal {
background: white;
padding: 24px 16px;
border-radius: 15px;
width: 300px;
}
.modal-title {
font-size: 24px;
font-weight: bold;
}
.close-wrapper {
text-align: right;
}
JS
import "./styles.css";
const open = document.getElementById("open");
const close = document.getElementById("close");
const modal = document.querySelector(".modal-wrapper");
open.onclick = () => {
modal.style.display = "flex";
};
close.onclick = () => {
modal.style.display = "none";
};
반응형
'2020 > Vanilla JavaScript' 카테고리의 다른 글
Javascript class, object (0) | 2020.09.20 |
---|---|
Javascript #prototype (0) | 2020.03.28 |
JavaScript #ES6 Class (0) | 2020.03.28 |
JavaScript #내장함수 reduce (0) | 2020.03.28 |
JavaScript #내장함수 (shift, pop, unshift, push, concat, join) (0) | 2020.03.28 |