| 1 |
wp.domReady(function () { |
| 2 |
document.querySelectorAll('.bkbg-ts-wrapper').forEach(function (wrapper) { |
| 3 |
/* ── Color-on-hover: grayscale toggle ─────────────────────────────── */ |
| 4 |
if (wrapper.classList.contains('bkbg-ts-color-on-hover')) { |
| 5 |
wrapper.querySelectorAll('.bkbg-ts-item img').forEach(function (img) { |
| 6 |
var parent = img.closest('.bkbg-ts-item'); |
| 7 |
parent.addEventListener('mouseenter', function () { img.style.filter = 'none'; }); |
| 8 |
parent.addEventListener('mouseleave', function () { img.style.filter = 'grayscale(100%)'; }); |
| 9 |
}); |
| 10 |
} |
| 11 |
|
| 12 |
/* ── Animate on scroll ──────────────────────────────────────────────── */ |
| 13 |
var items = wrapper.querySelectorAll('.bkbg-ts-item.bkbg-ts-anim'); |
| 14 |
if (!items.length) return; |
| 15 |
|
| 16 |
var io = new IntersectionObserver(function (entries) { |
| 17 |
entries.forEach(function (entry, idx) { |
| 18 |
if (entry.isIntersecting) { |
| 19 |
setTimeout(function () { |
| 20 |
entry.target.classList.add('bkbg-ts-visible'); |
| 21 |
}, idx * 60); |
| 22 |
io.unobserve(entry.target); |
| 23 |
} |
| 24 |
}); |
| 25 |
}, { threshold: 0.1 }); |
| 26 |
|
| 27 |
items.forEach(function (item) { io.observe(item); }); |
| 28 |
}); |
| 29 |
}); |
| 30 |
|