Alert.js是一个小型jQuery插件,用于创建受OS X启发的咆哮通知,5秒后自动关闭。
这些通知可以用于显示任何类型的警报、警告和通知,并确保您不必用丑陋的警报框覆盖设计精美的页面。
1.在jQuery库之后加载主脚本alert.js。
<script src="/path/to/cdn/jquery.min.js"></script> <script src="/path/to/alert.js"></script>
2.设置警报容器的样式。
.alert-container {
position: fixed;
top: 30px;
width: 50%;
display: flex;
flex-direction: column;
row-gap: 15px;
right: 10px;
}
@media only screen and (min-width: 600px) {
.alert-container {
width: 400px;
}
}
3.警报框所需的CSS样式。
.modal-alert {
box-shadow: 0px 4px 4px rgba(0, 0, 0, 0.25);
display: none;
padding: 20px 15px;
border-radius: 8px;
position: relative;
}
.modal-alert .content {
display: flex;
align-items: center;
}
.modal-alert .content svg {
opacity: 0.9;
margin: 0 10px;
}
.modal-alert h6 {
opacity: 0.9;
color: #fff;
font-weight: 600;
font-size: 16px;
}
.modal-alert .bar {
height: 2px;
left: 8px;
bottom: 0px;
background: rgb(255, 231, 15);
position: absolute;
border-radius: 4px 4px 0 0;
}
.progress {
animation: alertProgress 5s ease;
}
@keyframes alertProgress {
from {
width: 90%;
}
to {
width: 0;
}
}
4.显示INFORMATION(信息)警告框。
triggerAlert('This is an INFO notification');
5.显示ERROR(错误)警告框。
triggerAlert('This is an ERROR notification', 'error');
6.显示SUCCESS(成功)警告框。
triggerAlert('This is a SUCCESS notification', 'success');