-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotification Toast.html
75 lines (64 loc) · 2.01 KB
/
Notification Toast.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
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Notification Toast Messages</title>
<style>
.toast-container {
position: fixed;
top: 20px;
right: 20px;
max-width: 300px;
z-index: 1000;
}
.toast {
background-color: #333;
color: #fff;
padding: 15px 20px;
border-radius: 4px;
margin-bottom: 10px;
opacity: 0;
transform: translateY(-20px);
transition: all 0.3s ease-in-out;
}
.toast.show {
opacity: 1;
transform: translateY(0);
}
.toast-success {
background-color: #4CAF50;
}
.toast-error {
background-color: #F44336;
}
.toast-info {
background-color: #2196F3;
}
</style>
</head>
<body>
<button onclick="showToast('success', 'Operation completed successfully!')">Success Toast</button>
<button onclick="showToast('error', 'An error occurred. Please try again.')">Error Toast</button>
<button onclick="showToast('info', 'New update available.')">Info Toast</button>
<div class="toast-container"></div>
<script>
function showToast(type, message) {
const toastContainer = document.querySelector('.toast-container');
const toast = document.createElement('div');
toast.className = `toast toast-${type}`;
toast.textContent = message;
toastContainer.appendChild(toast);
// Trigger reflow to enable transition
toast.offsetHeight;
toast.classList.add('show');
setTimeout(() => {
toast.classList.remove('show');
setTimeout(() => {
toastContainer.removeChild(toast);
}, 300);
}, 3000);
}
</script>
</body>
</html>