| 1 |
(function () { |
| 2 |
'use strict'; |
| 3 |
|
| 4 |
function animateSkills() { |
| 5 |
var wraps = document.querySelectorAll('.bkbg-skills[data-animate="1"]'); |
| 6 |
if (!wraps.length) return; |
| 7 |
|
| 8 |
/* -- bars -- */ |
| 9 |
var bars = document.querySelectorAll('.bkbg-skills[data-animate="1"] .bkbg-skills-fill'); |
| 10 |
bars.forEach(function (el) { el.style.width = '0%'; }); |
| 11 |
|
| 12 |
/* -- circles -- */ |
| 13 |
var arcs = document.querySelectorAll('.bkbg-skills[data-animate="1"] .bkbg-skills-arc'); |
| 14 |
arcs.forEach(function (el) { |
| 15 |
var circ = parseFloat(el.getAttribute('data-circ')) || 0; |
| 16 |
el.style.strokeDashoffset = circ; |
| 17 |
}); |
| 18 |
|
| 19 |
var io = new IntersectionObserver(function (entries) { |
| 20 |
entries.forEach(function (entry) { |
| 21 |
if (!entry.isIntersecting) return; |
| 22 |
var wrap = entry.target; |
| 23 |
|
| 24 |
/* animate bars within this wrap */ |
| 25 |
var wrapBars = wrap.querySelectorAll('.bkbg-skills-fill'); |
| 26 |
wrapBars.forEach(function (fill) { |
| 27 |
var pct = parseFloat(fill.getAttribute('data-pct')) || 0; |
| 28 |
fill.style.transition = 'width 0.9s ease'; |
| 29 |
fill.style.width = pct + '%'; |
| 30 |
}); |
| 31 |
|
| 32 |
/* animate circle arcs within this wrap */ |
| 33 |
var wrapArcs = wrap.querySelectorAll('.bkbg-skills-arc'); |
| 34 |
wrapArcs.forEach(function (arc) { |
| 35 |
var pct = parseFloat(arc.getAttribute('data-pct')) || 0; |
| 36 |
var circ = parseFloat(arc.getAttribute('data-circ')) || 0; |
| 37 |
var target = circ - (pct / 100) * circ; |
| 38 |
arc.style.transition = 'stroke-dashoffset 1.2s ease'; |
| 39 |
arc.style.strokeDashoffset = target; |
| 40 |
}); |
| 41 |
|
| 42 |
io.unobserve(wrap); |
| 43 |
}); |
| 44 |
}, { threshold: 0.2 }); |
| 45 |
|
| 46 |
wraps.forEach(function (wrap) { io.observe(wrap); }); |
| 47 |
} |
| 48 |
|
| 49 |
if (document.readyState === 'loading') { |
| 50 |
document.addEventListener('DOMContentLoaded', animateSkills); |
| 51 |
} else { |
| 52 |
animateSkills(); |
| 53 |
} |
| 54 |
}()); |
| 55 |
|