Initial commit xmarticaims
This commit is contained in:
+23
@@ -0,0 +1,23 @@
|
||||
[data-anime-scroll-title].anime-scroll-title-ready [data-word] {
|
||||
will-change: transform, opacity;
|
||||
backface-visibility: hidden;
|
||||
}
|
||||
|
||||
/* splitText creates transformed word wrappers. Reapply the original title
|
||||
gradient to those wrappers so background-clip remains visible while moving. */
|
||||
[data-anime-scroll-title] [data-anime-title-gradient] [data-word] {
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
[data-anime-scroll-title] [data-anime-title-gradient-continuous] [data-word] {
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
[data-anime-scroll-title] [data-word] {
|
||||
opacity: 1 !important;
|
||||
transform: none !important;
|
||||
}
|
||||
}
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
import { animate } from '../../assets/vendor/animejs/modules/animation/index.js';
|
||||
import { splitText } from '../../assets/vendor/animejs/modules/text/index.js';
|
||||
import { remove, set, stagger } from '../../assets/vendor/animejs/modules/utils/index.js';
|
||||
|
||||
const titles = document.querySelectorAll('[data-anime-scroll-title]');
|
||||
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
|
||||
if (titles.length && !reduceMotion) {
|
||||
const initTitleAnimation = (title) => {
|
||||
const gradientSources = Array.from(title.querySelectorAll('[class*="bg-gradient-to-r"]')).map((element, index) => {
|
||||
element.setAttribute('data-anime-title-gradient', String(index));
|
||||
return {
|
||||
index,
|
||||
backgroundImage: window.getComputedStyle(element).backgroundImage,
|
||||
continuous: element.hasAttribute('data-anime-title-gradient-continuous'),
|
||||
};
|
||||
});
|
||||
|
||||
const split = splitText(title, {
|
||||
words: {
|
||||
wrap: 'clip',
|
||||
class: 'solutions-title-word',
|
||||
},
|
||||
accessible: true,
|
||||
});
|
||||
const words = split.words;
|
||||
|
||||
if (!words.length) {
|
||||
return;
|
||||
}
|
||||
|
||||
title.classList.add('anime-scroll-title-ready');
|
||||
|
||||
const applyTitleGradients = () => {
|
||||
gradientSources.forEach((gradient) => {
|
||||
const gradientElement = Array.from(
|
||||
title.querySelectorAll(`[data-anime-title-gradient="${gradient.index}"]`)
|
||||
).find((element) => element.querySelector('[data-word]'));
|
||||
|
||||
if (!gradientElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
const gradientRect = gradientElement.getBoundingClientRect();
|
||||
|
||||
gradientElement.querySelectorAll('[data-word]').forEach((word) => {
|
||||
word.style.backgroundImage = gradient.backgroundImage;
|
||||
|
||||
if (!gradient.continuous || gradientRect.width <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
const wordRect = word.getBoundingClientRect();
|
||||
word.style.backgroundSize = `${gradientRect.width}px 100%`;
|
||||
word.style.backgroundPosition = `${gradientRect.left - wordRect.left}px 0`;
|
||||
word.style.backgroundRepeat = 'no-repeat';
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
applyTitleGradients();
|
||||
|
||||
if ('ResizeObserver' in window && gradientSources.some((gradient) => gradient.continuous)) {
|
||||
const gradientResizeObserver = new ResizeObserver(() => {
|
||||
window.requestAnimationFrame(applyTitleGradients);
|
||||
});
|
||||
gradientResizeObserver.observe(title);
|
||||
}
|
||||
|
||||
set(words, { opacity: 0, y: '110%' });
|
||||
|
||||
const reveal = (origin) => {
|
||||
remove(words);
|
||||
set(words, { opacity: 0, y: origin });
|
||||
animate(words, {
|
||||
opacity: [0, 1],
|
||||
y: [origin, '0%'],
|
||||
duration: 760,
|
||||
delay: stagger(65),
|
||||
ease: 'out(4)',
|
||||
});
|
||||
};
|
||||
|
||||
const conceal = (destination) => {
|
||||
remove(words);
|
||||
animate(words, {
|
||||
opacity: 0,
|
||||
y: destination,
|
||||
duration: 440,
|
||||
delay: stagger(34, { from: 'last' }),
|
||||
ease: 'in(3)',
|
||||
});
|
||||
};
|
||||
|
||||
let lastScrollPosition = window.scrollY;
|
||||
let isVisible = false;
|
||||
let introObserver = null;
|
||||
|
||||
const revealWhenReady = (origin) => {
|
||||
if (title.id !== 'home-hero-title' || !document.getElementById('xmartica-intro')) {
|
||||
reveal(origin);
|
||||
return;
|
||||
}
|
||||
|
||||
introObserver = new MutationObserver(() => {
|
||||
if (!document.getElementById('xmartica-intro')) {
|
||||
introObserver.disconnect();
|
||||
introObserver = null;
|
||||
if (isVisible) {
|
||||
reveal(origin);
|
||||
}
|
||||
}
|
||||
});
|
||||
introObserver.observe(document.body, { childList: true });
|
||||
};
|
||||
|
||||
const viewportObserver = new IntersectionObserver((entries) => {
|
||||
entries.forEach((entry) => {
|
||||
const currentScrollPosition = window.scrollY;
|
||||
const isScrollingBackward = currentScrollPosition < lastScrollPosition;
|
||||
|
||||
if (entry.isIntersecting && !isVisible) {
|
||||
isVisible = true;
|
||||
revealWhenReady(isScrollingBackward ? '-110%' : '110%');
|
||||
} else if (!entry.isIntersecting && isVisible) {
|
||||
if (introObserver) {
|
||||
introObserver.disconnect();
|
||||
introObserver = null;
|
||||
}
|
||||
conceal(isScrollingBackward ? '110%' : '-110%');
|
||||
isVisible = false;
|
||||
}
|
||||
|
||||
lastScrollPosition = currentScrollPosition;
|
||||
});
|
||||
}, {
|
||||
threshold: 0.2,
|
||||
});
|
||||
|
||||
viewportObserver.observe(title);
|
||||
};
|
||||
|
||||
const initTitleAnimations = () => {
|
||||
titles.forEach(initTitleAnimation);
|
||||
};
|
||||
|
||||
if (document.fonts && document.fonts.ready) {
|
||||
document.fonts.ready.then(initTitleAnimations);
|
||||
} else {
|
||||
initTitleAnimations();
|
||||
}
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/**
|
||||
* Scroll-driven Anime.js animation for the front-page solutions title.
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
function xmartica_solutions_title_animation_assets() {
|
||||
if ( ! is_front_page() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$dir = get_template_directory() . '/parts/solutions-title-animation';
|
||||
$uri = get_template_directory_uri() . '/parts/solutions-title-animation';
|
||||
|
||||
wp_enqueue_style(
|
||||
'xmartica-solutions-title-animation',
|
||||
$uri . '/solutions-title-animation.css',
|
||||
array(),
|
||||
filemtime( $dir . '/solutions-title-animation.css' )
|
||||
);
|
||||
|
||||
wp_enqueue_script(
|
||||
'xmartica-solutions-title-animation',
|
||||
$uri . '/solutions-title-animation.js',
|
||||
array(),
|
||||
filemtime( $dir . '/solutions-title-animation.js' ),
|
||||
true
|
||||
);
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'xmartica_solutions_title_animation_assets' );
|
||||
|
||||
function xmartica_solutions_title_module_tag( $tag, $handle, $src ) {
|
||||
if ( 'xmartica-solutions-title-animation' !== $handle ) {
|
||||
return $tag;
|
||||
}
|
||||
|
||||
return '<script type="module" src="' . esc_url( $src ) . '"></script>';
|
||||
}
|
||||
add_filter( 'script_loader_tag', 'xmartica_solutions_title_module_tag', 10, 3 );
|
||||
Reference in New Issue
Block a user