SOURCE

console 命令行工具 X clear

                    
>
console
window.addEventListener('scroll',()=>{
    let header =document.querySelector('header')
    console.log(header.classList)
    header.classList.toggle('sticky',window.scrollTop>0)
})
<header>
    <a href="#" class="logo">Logo</a>
    <ul>
      <li><a href="#">首页</a></li>
      <li><a href="#">关于</a></li>
      <li><a href="#">服务</a></li>
      <li><a href="#">作品</a></li>
      <li><a href="#">联系</a></li>
    </ul>
  </header>
<section class="banner"></section>
* {
    margin: 0;
    padding: 0px;
}
body {
    background: #000;
    min-height: 200vh;
}

header {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 2;
    transition: .6s;
    padding: 20px 50px;
}

header .logo {
    position: relative;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    font-size: 2em;
    text-transform: uppercase;
    letter-spacing: 2px;
    transition: 0;
}

header.sticky {
    padding: 5px 100px ;
    background: #fff;
}

header ul {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
}

header ul li {
    position: relative;
    list-style: none;
}

header ul li a {
    position: relative;
    margin: 0 15px;
    text-decoration: none;
    color: #fff;
    letter-spacing: 2px;
    font-weight: 500px;
    transition: .5s;
}

.banner {
    position: relative;
    width: 100%;
    height: 100vh;
    background: url(https://goss.veer.com/creative/vcg/veer/800water/veer-133331298.jpg);
    background-size: cover;
}

header.sticky .logo,
header.sticky ul li a {
    color: #000;
}