| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
// Staggered entrance animation for HowTo steps |
| 5 |
if (!('IntersectionObserver' in window)) return; |
| 6 |
|
| 7 |
document.querySelectorAll('.bkbg-hs-steps').forEach(function (ol) { |
| 8 |
var steps = ol.querySelectorAll('.bkbg-hs-step'); |
| 9 |
if (!steps.length) return; |
| 10 |
|
| 11 |
// Mark each step for animation |
| 12 |
steps.forEach(function (step) { |
| 13 |
step.setAttribute('data-animate', ''); |
| 14 |
}); |
| 15 |
|
| 16 |
var io = new IntersectionObserver(function (entries) { |
| 17 |
entries.forEach(function (entry) { |
| 18 |
if (!entry.isIntersecting) return; |
| 19 |
var step = entry.target; |
| 20 |
// Get the index to stagger |
| 21 |
var idx = Array.prototype.indexOf.call(steps, step); |
| 22 |
setTimeout(function () { |
| 23 |
step.setAttribute('data-animate', 'in'); |
| 24 |
}, idx * 100); |
| 25 |
io.unobserve(step); |
| 26 |
}); |
| 27 |
}, { threshold: 0.15, rootMargin: '0px 0px -40px 0px' }); |
| 28 |
|
| 29 |
steps.forEach(function (step) { |
| 30 |
io.observe(step); |
| 31 |
}); |
| 32 |
}); |
| 33 |
})(); |
| 34 |
|