| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
// Chat Bubbles — animate messages into view on scroll |
| 5 |
function initChatBubbles() { |
| 6 |
var containers = document.querySelectorAll('.bkbg-chat-container'); |
| 7 |
if (!containers.length) return; |
| 8 |
|
| 9 |
if (!('IntersectionObserver' in window)) return; |
| 10 |
|
| 11 |
var obs = new IntersectionObserver(function (entries) { |
| 12 |
entries.forEach(function (entry) { |
| 13 |
if (!entry.isIntersecting) return; |
| 14 |
var messages = entry.target.querySelectorAll('.bkbg-chat-msg'); |
| 15 |
messages.forEach(function (msg, idx) { |
| 16 |
setTimeout(function () { |
| 17 |
msg.style.opacity = '1'; |
| 18 |
msg.style.transform = 'translateY(0)'; |
| 19 |
}, idx * 80); |
| 20 |
}); |
| 21 |
obs.unobserve(entry.target); |
| 22 |
}); |
| 23 |
}, { threshold: 0.15 }); |
| 24 |
|
| 25 |
containers.forEach(function (container) { |
| 26 |
var messages = container.querySelectorAll('.bkbg-chat-msg'); |
| 27 |
messages.forEach(function (msg) { |
| 28 |
msg.style.opacity = '0'; |
| 29 |
msg.style.transform = 'translateY(16px)'; |
| 30 |
msg.style.transition = 'opacity 0.35s ease, transform 0.35s ease'; |
| 31 |
}); |
| 32 |
obs.observe(container); |
| 33 |
}); |
| 34 |
} |
| 35 |
|
| 36 |
if (document.readyState === 'loading') { |
| 37 |
document.addEventListener('DOMContentLoaded', initChatBubbles); |
| 38 |
} else { |
| 39 |
initChatBubbles(); |
| 40 |
} |
| 41 |
}()); |
| 42 |
|