| 1 |
/** |
| 2 |
* Timeline Block Frontend |
| 3 |
* Handles scroll animations |
| 4 |
*/ |
| 5 |
(function() { |
| 6 |
'use strict'; |
| 7 |
|
| 8 |
function initTimeline() { |
| 9 |
var timelines = document.querySelectorAll('.bkbg-tl-wrap[data-animate="1"]'); |
| 10 |
|
| 11 |
if (!timelines.length) return; |
| 12 |
|
| 13 |
// Check if IntersectionObserver is supported |
| 14 |
if (!('IntersectionObserver' in window)) { |
| 15 |
// Fallback: show all items immediately |
| 16 |
timelines.forEach(function(timeline) { |
| 17 |
var items = timeline.querySelectorAll('.bkbg-tl-item'); |
| 18 |
items.forEach(function(item) { |
| 19 |
item.classList.add('is-visible'); |
| 20 |
}); |
| 21 |
}); |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
timelines.forEach(function(timeline) { |
| 26 |
var items = timeline.querySelectorAll('.bkbg-tl-item'); |
| 27 |
|
| 28 |
var observer = new IntersectionObserver(function(entries) { |
| 29 |
entries.forEach(function(entry) { |
| 30 |
if (entry.isIntersecting) { |
| 31 |
// Add staggered delay based on item index |
| 32 |
var item = entry.target; |
| 33 |
var index = Array.from(items).indexOf(item); |
| 34 |
|
| 35 |
setTimeout(function() { |
| 36 |
item.classList.add('is-visible'); |
| 37 |
}, index * 150); |
| 38 |
|
| 39 |
// Stop observing once visible |
| 40 |
observer.unobserve(item); |
| 41 |
} |
| 42 |
}); |
| 43 |
}, { |
| 44 |
threshold: 0.2, |
| 45 |
rootMargin: '0px 0px -50px 0px' |
| 46 |
}); |
| 47 |
|
| 48 |
items.forEach(function(item) { |
| 49 |
observer.observe(item); |
| 50 |
}); |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
// Initialize on DOM ready |
| 55 |
if (document.readyState === 'loading') { |
| 56 |
document.addEventListener('DOMContentLoaded', initTimeline); |
| 57 |
} else { |
| 58 |
initTimeline(); |
| 59 |
} |
| 60 |
})(); |
| 61 |
|