Scroll · 20 of 34
Gradient Shift
A gradient sweeps across the text once it enters view, using background-clip: text. Animates background-position over a wide gradient.
<section class="gradient-shift-section">
<h2 class="gradient-text">Gradient Shift</h2>
</section>
.gradient-shift-section {
min-height: 35vh;
display: flex;
align-items: center;
justify-content: center;
}
.gradient-text {
font-size: 2.5rem;
background: linear-gradient(90deg, #f0f0f5, #7c5cff, #a78bfa);
background-size: 200% 100%;
background-position: 100% 50%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
transition: background-position 1s cubic-bezier(0.16, 1, 0.3, 1);
}
.gradient-shift-section.in-view .gradient-text {
background-position: 0% 50%;
}
var section = document.querySelector('.gradient-shift-section');
new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
entry.target.classList.toggle('in-view', entry.isIntersecting);
});
}, { threshold: 0.25 }).observe(section);