Files
JoshHeaps.Net/JoshHeaps.Net/wwwroot/js/opacityUpdateObserver.js
T
2024-11-22 14:06:04 -07:00

27 lines
668 B
JavaScript

let thresholds = [];
for (let i = 0; i <= 1.0; i += 0.01) {
thresholds.push(i);
}
const percentThresholdsOptions = {
root: null,
threshold: thresholds,
};
const updateOpacityCallback = (entries) => {
entries.forEach(entry => {
entry.target.style.opacity = entry.intersectionRatio;
});
};
const opacityObserver = new IntersectionObserver(updateOpacityCallback, percentThresholdsOptions);
window.addEventListener('load', createObserver);
function createObserver() {
const targetImages = document.querySelectorAll(".projectImage");
targetImages.forEach(targetImage => {
opacityObserver.observe(targetImage);
});
};