| 1 |
(function () { |
| 2 |
function animateFunnel(wrap) { |
| 3 |
var stages = wrap.querySelectorAll('.bkbg-fn-stage-bar'); |
| 4 |
stages.forEach(function (stage) { |
| 5 |
var targetWidth = stage.dataset.targetWidth; |
| 6 |
if (!targetWidth) return; |
| 7 |
stage.style.width = '0%'; |
| 8 |
stage.style.opacity = '0'; |
| 9 |
stage.style.transition = 'none'; |
| 10 |
requestAnimationFrame(function () { |
| 11 |
requestAnimationFrame(function () { |
| 12 |
stage.style.transition = 'width 0.55s cubic-bezier(0.25,0.8,0.25,1), opacity 0.3s'; |
| 13 |
stage.style.width = targetWidth; |
| 14 |
stage.style.opacity = '1'; |
| 15 |
}); |
| 16 |
}); |
| 17 |
}); |
| 18 |
} |
| 19 |
|
| 20 |
function init() { |
| 21 |
var wraps = document.querySelectorAll('.bkbg-fn-card'); |
| 22 |
if (!wraps.length) return; |
| 23 |
|
| 24 |
var observer = new IntersectionObserver(function (entries) { |
| 25 |
entries.forEach(function (entry) { |
| 26 |
if (!entry.isIntersecting) return; |
| 27 |
animateFunnel(entry.target); |
| 28 |
observer.unobserve(entry.target); |
| 29 |
}); |
| 30 |
}, { threshold: 0.15 }); |
| 31 |
|
| 32 |
wraps.forEach(function (wrap) { |
| 33 |
/* Prepare target widths from inline style, then reset to 0 for animation */ |
| 34 |
var stages = wrap.querySelectorAll('.bkbg-fn-stage-bar'); |
| 35 |
stages.forEach(function (stage) { |
| 36 |
var currentW = stage.style.width || '100%'; |
| 37 |
stage.dataset.targetWidth = currentW; |
| 38 |
stage.style.width = '0%'; |
| 39 |
stage.style.opacity = '0'; |
| 40 |
}); |
| 41 |
observer.observe(wrap); |
| 42 |
}); |
| 43 |
} |
| 44 |
|
| 45 |
if (document.readyState === 'loading') { |
| 46 |
document.addEventListener('DOMContentLoaded', init); |
| 47 |
} else { |
| 48 |
init(); |
| 49 |
} |
| 50 |
})(); |
| 51 |
|