fix(notification): correct bell animation + automatically close notification zone on clear
This commit is contained in:
@@ -123,15 +123,17 @@
|
|||||||
|
|
||||||
@keyframes bellRing {
|
@keyframes bellRing {
|
||||||
0%, 100% { transform: rotate(0deg); }
|
0%, 100% { transform: rotate(0deg); }
|
||||||
15% { transform: rotate(14deg); }
|
13% { transform: rotate(22deg); }
|
||||||
30% { transform: rotate(-14deg); }
|
26% { transform: rotate(-22deg); }
|
||||||
45% { transform: rotate(8deg); }
|
39% { transform: rotate(14deg); }
|
||||||
60% { transform: rotate(-8deg); }
|
52% { transform: rotate(-14deg); }
|
||||||
75% { transform: rotate(3deg); }
|
65% { transform: rotate(8deg); }
|
||||||
|
78% { transform: rotate(-8deg); }
|
||||||
|
91% { transform: rotate(3deg); }
|
||||||
}
|
}
|
||||||
|
|
||||||
.notif-bell-btn.ring i {
|
.notif-bell-btn.ring {
|
||||||
animation: bellRing 0.6s ease;
|
animation: bellRing 1s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.notif-panel {
|
.notif-panel {
|
||||||
|
|||||||
@@ -47,8 +47,7 @@ const notifications = (() => {
|
|||||||
// Close on outside click
|
// Close on outside click
|
||||||
document.addEventListener('click', (e) => {
|
document.addEventListener('click', (e) => {
|
||||||
if (!wrapper.contains(e.target)) {
|
if (!wrapper.contains(e.target)) {
|
||||||
wrapper.classList.remove('open');
|
close();
|
||||||
bellBtn.classList.remove('active');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -61,6 +60,13 @@ const notifications = (() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
const bellBtn = $('notif-bell-btn');
|
||||||
|
const wrapper = $('notif-wrapper');
|
||||||
|
wrapper.classList.remove('open');
|
||||||
|
bellBtn.classList.remove('active');
|
||||||
|
}
|
||||||
|
|
||||||
/* ── badge helpers ──────────────────────────────────────── */
|
/* ── badge helpers ──────────────────────────────────────── */
|
||||||
function _incrementBadge() {
|
function _incrementBadge() {
|
||||||
_badgeCount++;
|
_badgeCount++;
|
||||||
@@ -73,12 +79,13 @@ const notifications = (() => {
|
|||||||
}
|
}
|
||||||
function _renderBadge() {
|
function _renderBadge() {
|
||||||
const badge = $('notif-badge');
|
const badge = $('notif-badge');
|
||||||
|
console.log(`badge`, badge);
|
||||||
if (!badge) return;
|
if (!badge) return;
|
||||||
if (_badgeCount > 0) {
|
if (_badgeCount > 0) {
|
||||||
badge.style.display = '';
|
badge.classList.remove("hidden");
|
||||||
badge.textContent = _badgeCount > 99 ? '99+' : _badgeCount;
|
badge.textContent = _badgeCount > 99 ? '99+' : _badgeCount;
|
||||||
} else {
|
} else {
|
||||||
badge.style.display = 'none';
|
badge.classList.add("hidden");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function _ringBell() {
|
function _ringBell() {
|
||||||
@@ -312,6 +319,11 @@ const notifications = (() => {
|
|||||||
body.querySelectorAll('.notif-item').forEach(el => el.remove());
|
body.querySelectorAll('.notif-item').forEach(el => el.remove());
|
||||||
_clearBadge();
|
_clearBadge();
|
||||||
_showEmptyIfNeeded();
|
_showEmptyIfNeeded();
|
||||||
|
// automatically close notification center on clear
|
||||||
|
setTimeout(
|
||||||
|
()=> { close(); },
|
||||||
|
600
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ── util ───────────────────────────────────────────────── */
|
/* ── util ───────────────────────────────────────────────── */
|
||||||
|
|||||||
Reference in New Issue
Block a user