header fade out test

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Scroll Test for StackOverflow</title>
    <style>
        .header-background{
            height: 500px;
            background-color:red;
        }
        .logo-container{
            position: fixed;
            top:2%;
            left: 50%;
            transform: translate(-50%, 0);
            width: 80px;
            height: 80px;
            background-color: blue;
        }
        .logo.logo-container{
            position: absolute;
        }
        .container{
            height: 2000px;
        }

        @keyframes fade-in{
            from{opacity:0;}
            to{opacity: 1;}
        }
        @keyframes fade-out{
            from{opacity: 1;}
            to{opacity: 0;} 
        }
        .fade-in{
            opacity: 0;
            animation-name: fade-in;
            animation-duration: 0.4s;
            animation-timing-function: ease-out;
            animation-fill-mode: forwards;
        }
        .fade-out{
            opacity: 1;
            animation-name: fade-out;
            animation-duration: 0.2s;
            animation-timing-function: ease-out;
            animation-fill-mode: forwards;
        }
    </style>
</head>
<body>


    <div class="container">
        <div class="headerhide" id="headerhide">
            <div class="logo-container">
                <div class="logo"></div>
            </div>
        </div>

        <div class="header-background" id="region"></div>
    </div>

    <script>
            const header = document.getElementById("headerhide");
            const region = document.querySelector(".header-background");

            const observer = new IntersectionObserver(([entry]) =>{
                header.classList.toggle("fade-out", !entry.isIntersecting);
                header.classList.toggle("fade-in", entry.isIntersecting);
                
           ...