CSS滚动文字填充效果

by HDL52

HTML

<link rel="stylesheet" href="styles.css">

    <div class="spacer">向下滚动查看效果 ↓</div>
    
    <div class="text-container">
        <span>创意设计师数字营销专家品牌策略顾问 结合创新思维与专业技能,为您的品牌创造独特的数字体验,释放无限可能的商业价值。</span>
    </div>
    
    <div class="spacer">END</div>

CSS

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Arial", sans-serif;
    background: #0a0a0a;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.spacer {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: #666;
}

.text-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    position: relative;
}

.text-container span {
    color: hsla(0, 0%, 100%, 0.2) !important;
    background-clip: text;
    background-size: 0 100%;
    background-repeat: no-repeat;
    background-image: linear-gradient(90deg, white, white);
    animation: scroll-reveal linear forwards;
    animation-timeline: view();
}

.text-container .animated-text span {
    animation-range-start: cover 20vh;
    animation-range-end: cover 30vh;
}

.text-container .subtitle span {
    animation-range-start: cover 22.5vh;
    animation-range-end: cover 50vh;
}

.animated-text {
    font-size: clamp(2rem, 8vw, 6rem);
    font-weight: 900;
    line-height: 1.1;
    text-align: center;
    margin-bottom: 2rem;
}

.subtitle {
    font-size: clamp(1rem, 3vw, 1.5rem);
    font-weight: 300;
    text-align: center;
    max-width: 800px;
    line-height: 1.6;
}

/* 额外的视觉效果 */
.text-container::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(
        circle at center,
        rgba(255, 255, 255, 0.03) 0%,
        transparent 70%
    );
    pointer-events: none;
}

@keyframes scroll-reveal {
    to {
        background-size: 100% 100%;
    }
}