250x250
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- image
- css3
- button
- 비전공자
- html5
- 애니메이션
- 개발자
- MAC
- front-end
- IOS
- 풀스택
- CSS
- HTML
- jQuery
- xcode
- php
- javascript
- keyframes
- 자바스크립트
- iOS 개발자
- 비전공 개발자
- Animation
- 백엔드
- react
- hover
- ipad
- iPhone
- 프론트엔드
- SWIFT
- effect
Archives
- Today
- Total
비전공자 개발일기
Toast Notification 본문
728x90
SMALL
<!DOCTYPE html>
<html lang="ko">
<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>TOAST NOTIFICATION</title>
<link rel="stylesheet" href="style.css">
<script defer src="main.js"></script>
</head>
<body>
<div id="toasts"></div>
<button type="button" class="btn" id="button">Show Notification</button>
</body>
</html>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400&display=swap');
* {
box-sizing: border-box;
}
body {
background-color: rebeccapurple;
font-family: 'Poppins', sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
overflow: hidden;
margin: 0;
}
.btn {
background-color: #ffffff;
color: rebeccapurple;
font-family: inherit;
font-weight: bold;
padding: 1rem;
border-radius: 5px;
border: none;
cursor: pointer;
}
.btn:focus {
outline: none;
}
.btn:active {
transform: scale(0.98);
}
#toasts {
position: fixed;
bottom: 10px;
right: 10px;
display: flex;
flex-direction: column;
align-items: flex-end;
}
.toast {
background-color: #fff;
border-radius: 5px;
padding: 1rem 2rem;
margin: 0.5rem;
}
.toast.info {
color: rebeccapurple;
}
.toast.success {
color: green;
}
.toast.error {
color: red;
}
const button = document.getElementById('button')
const toasts = document.getElementById('toasts')
const messages = [
'Message One',
'Message Two',
'Message Three',
'Message Four',
]
const types = ['info', 'success', 'error']
button.addEventListener('click', () => createNotification())
function createNotification(message = null, type = null) {
const notif = document.createElement('div')
notif.classList.add('toast')
notif.classList.add(type ? type : getRandomType())
notif.innerText = message ? message : getRandomMessage()
toasts.appendChild(notif)
setTimeout(() => {
notif.remove()
}, 3000)
}
function getRandomMessage() {
return messages[Math.floor(Math.random() * messages.length)]
}
function getRandomType() {
return types[Math.floor(Math.random() * types.length)]
}
728x90
LIST
'Javascript' 카테고리의 다른 글
Analog Clock (0) | 2022.07.03 |
---|---|
Automatic Image Slider (0) | 2022.06.30 |
Word Counter (0) | 2022.06.20 |
Background color picker (0) | 2022.06.18 |
Date Calculator (0) | 2022.06.15 |