diff --git a/js/animations.js b/js/animations.js index fc9dbf7..f451f8a 100644 --- a/js/animations.js +++ b/js/animations.js @@ -1 +1 @@ -const observer=new IntersectionObserver(a=>{a.forEach(a=>{a.isIntersecting&&(a.target.classList.contains("anim-slide-right-appear")?a.target.classList.add("slide-right-appear"):a.target.classList.contains("anim-slide-up-appear")?a.target.classList.add("slide-up-appear"):a.target.classList.contains("anim-appear")?a.target.classList.add("appear"):a.target.classList.contains("anim-slide-down-appear")?a.target.classList.add("slide-down-appear"):a.target.classList.contains("anim-slide-in-place-right")?a.target.classList.add("slide-in-place-right"):a.target.classList.contains("anim-gallery-staggered-appear")?applyCssToChildren(a,"staggered-appear"):a.target.classList.contains("anim-slide-left-appear")&&a.target.classList.add("slide-left-appear"))})});function applyDelayToChildren(a,e){a=Array.from(a.children);let s=1;a.forEach(a=>{a.style.transitionDelay=s*e+"s",s++})}function applyCssToChildren(a,e){Array.from(a.target.children).forEach(a=>{a.classList.add(e)})}function preprocessTargets(){document.querySelectorAll(".anim-gallery-staggered-appear").forEach(a=>{applyDelayToChildren(a,.1)})}var genesis;void 0===genesis&&(genesis=313,console.log("Close the world, .txen eht nepO :: genesis by arbeit studio"));preprocessTargets();const query=".anim-slide-down-appear,.anim-slide-right-appear,.anim-slide-up-appear,.anim-appear,.anim-slide-in-place-right,.anim-gallery-staggered-appear,.anim-slide-left-appear";let targets=document.querySelectorAll(query);targets.forEach(a=>{observer.observe(a)}); \ No newline at end of file +const animationCN=["anim-slide-right-appear","anim-slide-up-appear","anim-appear","anim-slide-down-appear","anim-slide-in-place-right","anim-gallery-staggered-appear","anim-slide-left-appear"];function buildQuery(){let a="";return animationCN.forEach(e=>{a+=`.${e},`}),a}function addMatchingFunction(a){a.isIntersecting&&animationCN.forEach(e=>{a.target.classList.contains(e)&&a.target.classList.add(e.replace("anim-",""))})}const observer=new IntersectionObserver(e=>{e.forEach(e=>addMatchingFunction(e))});function applyDelayToChildren(e,a){e=Array.from(e.children);let r=1;e.forEach(e=>{e.style.transitionDelay=r*a+"s",r++})}function applyCssToChildren(e,a){Array.from(e.target.children).forEach(e=>{e.classList.add(a)})}function preprocessTargets(){document.querySelectorAll(".anim-gallery-staggered-appear").forEach(e=>{applyDelayToChildren(e,.1)})}var genesis;void 0===genesis&&(genesis=313,console.log("Close the world, .txen eht nepO :: genesis by arbeit studio"));preprocessTargets();const query=buildQuery();let targets=document.querySelectorAll(query);targets.forEach(e=>{observer.observe(e)}); \ No newline at end of file diff --git a/scripts/animations.js b/scripts/animations.js index 40357af..2f6b969 100644 --- a/scripts/animations.js +++ b/scripts/animations.js @@ -7,26 +7,34 @@ * genesis/scripts/animations.js */ -const observer = new IntersectionObserver(entries => { - entries.forEach(entry => { - if (entry.isIntersecting) { - if (entry.target.classList.contains("anim-slide-right-appear")) { - entry.target.classList.add("slide-right-appear"); - } else if (entry.target.classList.contains("anim-slide-up-appear")) { - entry.target.classList.add("slide-up-appear"); - } else if (entry.target.classList.contains("anim-appear")) { - entry.target.classList.add("appear"); - } else if (entry.target.classList.contains("anim-slide-down-appear")) { - entry.target.classList.add("slide-down-appear"); - } else if (entry.target.classList.contains("anim-slide-in-place-right")) { - entry.target.classList.add("slide-in-place-right"); - } else if(entry.target.classList.contains("anim-gallery-staggered-appear")) { - applyCssToChildren(entry, "staggered-appear"); - } else if (entry.target.classList.contains("anim-slide-left-appear")) { - entry.target.classList.add("slide-left-appear"); - } - } +const animationCN = [ + "anim-slide-right-appear", + "anim-slide-up-appear", + "anim-appear", + "anim-slide-down-appear", + "anim-slide-in-place-right", + "anim-gallery-staggered-appear", + "anim-slide-left-appear" +]; + +function buildQuery() { + let query = ""; + animationCN.forEach((an) => { + query += `.${an},`; }); + return query; +} + +function addMatchingFunction(e) { + if (e.isIntersecting) + animationCN.forEach((an) => { + if (e.target.classList.contains(an)) + e.target.classList.add(an.replace("anim-", "")); + }); +} + +const observer = new IntersectionObserver(entries => { + entries.forEach(entry => addMatchingFunction(entry)); }); function applyDelayToChildren(parent, multiplier) { @@ -54,7 +62,7 @@ function preprocessTargets() { var genesis = typeof genesis !== 'undefined' ? genesis : (genesis = 313, console.log("Close the world, .txen eht nepO :: genesis by arbeit studio"), genesis); preprocessTargets(); -const query = ".anim-slide-down-appear,.anim-slide-right-appear,.anim-slide-up-appear,.anim-appear,.anim-slide-in-place-right,.anim-gallery-staggered-appear,.anim-slide-left-appear"; +const query = buildQuery(); let targets = document.querySelectorAll(query); targets.forEach(target => { observer.observe(target);