| 1 |
wp.domReady(function () { |
| 2 |
document.querySelectorAll('.bkbg-vt-wrapper').forEach(function (wrapper) { |
| 3 |
/* ── Video click → iframe inject ──────────────────────────────────── */ |
| 4 |
wrapper.querySelectorAll('.bkbg-vt-video-wrap').forEach(function (wrap) { |
| 5 |
wrap.addEventListener('click', function () { |
| 6 |
var embedUrl = wrap.getAttribute('data-embed'); |
| 7 |
if (!embedUrl) return; |
| 8 |
|
| 9 |
var iframe = document.createElement('iframe'); |
| 10 |
iframe.src = embedUrl; |
| 11 |
iframe.allow = 'autoplay; fullscreen'; |
| 12 |
iframe.allowFullscreen = true; |
| 13 |
|
| 14 |
/* clear thumbnail + overlay, inject iframe */ |
| 15 |
while (wrap.firstChild) { wrap.removeChild(wrap.firstChild); } |
| 16 |
wrap.appendChild(iframe); |
| 17 |
wrap.style.cursor = 'default'; |
| 18 |
}); |
| 19 |
}); |
| 20 |
|
| 21 |
/* ── Animate on scroll ──────────────────────────────────────────────── */ |
| 22 |
var cards = wrapper.querySelectorAll('.bkbg-vt-card.bkbg-vt-anim'); |
| 23 |
if (!cards.length) return; |
| 24 |
|
| 25 |
var io = new IntersectionObserver(function (entries) { |
| 26 |
entries.forEach(function (entry, idx) { |
| 27 |
if (entry.isIntersecting) { |
| 28 |
setTimeout(function () { |
| 29 |
entry.target.classList.add('bkbg-vt-visible'); |
| 30 |
}, idx * 90); |
| 31 |
io.unobserve(entry.target); |
| 32 |
} |
| 33 |
}); |
| 34 |
}, { threshold: 0.1 }); |
| 35 |
|
| 36 |
cards.forEach(function (card) { io.observe(card); }); |
| 37 |
}); |
| 38 |
}); |
| 39 |
|