HTML
<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style>
.toast {
flex-basis: 0;
cursor: pointer;
box-sizing: border-box;
display: none;
width: 100%;
max-width: 640px;
font-size: 0.825em;
border-top-right-radius: 5px;
border-top-left-radius: 5px;
background: #ffffff;
z-index: 1051;
box-shadow: 0 2.8px 2.2px rgba(0, 0, 0, 0.02), 0 6.7px 5.3px rgba(0, 0, 0, 0.028), 0 12.5px 10px rgba(0, 0, 0, 0.035), 0 22.3px 17.9px rgba(0, 0, 0, 0.042), 0 41.8px 33.4px rgba(0, 0, 0, 0.05), 0 100px 80px rgba(0, 0, 0, 0.07);
transition: 0.2s ease-in;
}
@media (min-width:640px) {
.toast {
border-radius: 5px;
margin-bottom: 0.5em;
}
}
.toast:not(:last-child) {
margin-bottom: 2rem;
}
.toast--active {
display: flex;
-webkit-animation: slidein--bottom 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
animation: slidein--bottom 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55) forwards;
}
.toast--warning {
background: #bf360c;
color: white;
}
.toast--success {
background: #43a047;
color: white;
}
.toast__container {
box-sizing: border-box;
padding: 0em 1em;
position: fixed;
width: 100%;
max-width: 640px;
margin: 0 auto;
display: flex;
flex-flow: column;
bottom: 0;
left: 0;
right: 0;
align-items: center;
justify-content: center;
}
@media (min-width:640px) {
.toast__container {
padding: 0 1em;
}
}
@media (min-width:1024px) {
.toast__container {
left: initial;
right: 0;
}
}
.toast__icon {
height: 60px;
width: 60px;
box-sizing: border-box;
padding: 1em;
display: none;
align-items: center;
justify-content: center;
}
.toast__icon svg {
height: 100%;
}
@media (min-width:640px) {
.toast__icon {
display: flex;
}
}
.toast__icon ~ .toast__content {
padding: 1em;
}
@media (min-width:640px) {
.toast__icon ~ .toast__content {
padding: 1em 1em 1em 0;
}
}
.toast__content {
box-sizing: border-box;
padding: 1em;
}
.toast__content h2 {
margin: 0 0 0.25em 0;
padding: 0;
font-size: 1.2em;
}
.toast__content p {
margin: 0;
padding: 0;
font-size: 1em;
}
@-webkit-keyframes slidein--bottom {
0% {
opacity: 0;
transform: translateY(100%);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
@keyframes slidein--bottom {
0% {
opacity: 0;
transform: translateY(100%);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
</style>
</head>
<body>
<div class="toast__container">
<div id="info-alert" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast__icon">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="info-circle" class="svg-inline--fa fa-info-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path fill="currentColor" d="M256 8C119.043 8 8 119.083 8 256c0 136.997 111.043 248 248 248s248-111.003 248-248C504 119.083 392.957 8 256 8zm0 110c23.196 0 42 18.804 42 42s-18.804 42-42 42-42-18.804-42-42 18.804-42 42-42zm56 254c0 6.627-5.373 12-12 12h-88c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h12v-64h-12c-6.627 0-12-5.373-12-12v-24c0-6.627 5.373-12 12-12h64c6.627 0 12 5.373 12 12v100h12c6.627 0 12 5.373 12 12v24z"></path>
</svg>
</div>
<div class="toast__content">
<h2 class="toast__title">info</h2>
<p class="toast__content">content</p>
</div>
</div>
<div id="warning-alert" class="toast toast--warning" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast__icon">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-circle" class="svg-inline--fa fa-exclamation-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path fill="currentColor" d="M504 256c0 136.997-111.043 248-248 248S8 392.997 8 256C8 119.083 119.043 8 256 8s248 111.083 248 248zm-248 50c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z"></path>
</svg>
</div>
<div class="toast__content">
<h2 class="toast__title">warning</h2>
<p class="toast__content">content</p>
</div>
</div>
<div id="success-alert" class="toast toast--success" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast__icon">
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="check-circle" class="svg-inline--fa fa-check-circle fa-w-16" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
<path fill="currentColor" d="M504 256c0 136.967-111.033 248-248 248S8 392.967 8 256 119.033 8 256 8s248 111.033 248 248zM227.314 387.314l184-184c6.248-6.248 6.248-16.379 0-22.627l-22.627-22.627c-6.248-6.249-16.379-6.249-22.628 0L216 308.118l-70.059-70.059c-6.248-6.248-16.379-6.248-22.628 0l-22.627 22.627c-6.248 6.248-6.248 16.379 0 22.627l104 104c6.249 6.249 16.379 6.249 22.628.001z"></path>
</svg>
</div>
<div class="toast__content">
<h2 class="toast__title">success</h2>
<p class="toast__content">content</p>
</div>
</div>
</div>
</body>
</html>
JAVASCRIPT
/**
* alert 메시지
* @param type String 'info' : i , 'success' : s , 'warning' : w
* @param title String 제목
* @param content String 내용
* @param timeout Number 시간
*/
const onAlert = ( type = 'i' ,title = 'system' , content = 'wow alert' , timeout = 3000) => {
let $toastTimeout;
let $target;
if(type === 's'){
$target = $('#success-alert');
}else if(type === 'w'){
$target = $('#warning-alert');
}else{
$target = $('#info-alert');
}
const $setClass = "toast--active";
const $con = $target.find('.toast__content');
const $title = $con.find('.toast__title');
const $content = $con.find('.toast__content');
$target.addClass($setClass)
$title.html(title);
$content.html(content);
$toastTimeout = setTimeout(() => {
$target.removeClass($setClass);
}, timeout)
$target.click(() => {
$target.removeClass($setClass);
clearTimeout($toastTimeout);
})
}
사용법
const start = () => {
onAlert('w','시스템 메시지', '에러발생! ');
}
오른쪽 아래에 뜸
'JavaScript > jQuery' 카테고리의 다른 글
[jQuery] ajax 관련 (0) | 2024.07.16 |
---|