/ Gists / CSS View function
On gists

CSS View function

CSS CSS trick

demo.txt Raw #

https://jsbin.com/jegerowode/edit?html,output

index.html Raw #

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>View Animation Demo</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 0;
        }
        .spacer {
            height: 200vh;
            background: linear-gradient(to bottom, #e0e0e0, #ffffff);
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
        }
        .card {
            background: #f4f4f4;
            margin-bottom: 20px;
            padding: 20px;
            border-radius: 8px;
            opacity: 0;
            transform: translateY(20px);
        }
        @keyframes fadeInUp {
            from { 
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        .card:nth-child(1) { 
            animation: fadeInUp linear forwards;
            animation-timeline: view();
            animation-range: entry 100%;
            animation-iteration-count: 1;
            background: red;
        }
        .card:nth-child(2) { 
            animation: fadeInUp linear forwards;
            animation-timeline: view();
            animation-range: entry 20%;
            animation-iteration-count: 1;
          background: green;
        }
        .card:nth-child(3) { 
            animation: fadeInUp linear forwards;
            animation-timeline: view();
            animation-range: entry 50%;
            animation-iteration-count: 1;
          background: blue;
        }
    </style>
</head>
<body>
    <div class="spacer"></div>
    <div class="container">
        <div class="card">
            <h2>One-Time Animation</h2>
            <p>Animace provedena pouze jednou</p>
        </div>
        <div class="card">
            <h2>One-Time Delayed Start</h2>
            <p>Animace provedena pouze jednou po 20% vstupu</p>
        </div>
        <div class="card">
            <h2>One-Time Delayed Start</h2>
            <p>Animace provedena pouze jednou po 50% vstupu</p>
        </div>
    </div>
</body>
</html>