• 滚动渐变导航栏


    实现导航栏固定顶部,且滚动渐变的效果

    实现效果
    在这里插入图片描述

    准备html

    vscode可利用快捷输入 header>a+ul>li*3>a+tab

    DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Documenttitle>
        <link rel="stylesheet" href="style.css">
    head>
    <body>
        <header>
            <a href="#" class="logo">Logoa>
            <ul>
                <li><a href="#">Homea>li>
                <li><a href="#">Abouta>li>
                <li><a href="#">Contacta>li>
            ul>
        header>
        <section class="banner">section>
        <script type="text/javascript">
            window.addEventListener("scroll",function(){
                let header = document.querySelector("header");
                header.classList.toggle("sticky",window.scrollY>0)
            })
        script>
    body>
    html>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    准备css

    *{
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }
    body{
        background-color: #000;
        min-height: 200vh;
    }
    header{
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        transition: .6s;
        padding: 40px 100px;
        z-index: 99;
    }
    header.sticky{
        padding: 5px 100px;
        background: #fff;
    }
    header.sticky .logo,
    header.sticky ul li a{
        color: #000;
    }
    header .logo{
        position: relative;
        font-weight: 700;
        color: #fff;
        text-decoration: none;
        font-size: 2em;
        text-transform: uppercase;
        letter-spacing: 2px;
        transition: .6s;
    }
    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: .6s;
    }
    .banner{
        position: relative;
        width: 100%;
        height: 100vh;
        background: url("bg.png");
        background-size: cover;
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
  • 相关阅读:
    基于Delta Lake构建数据湖仓体系
    Mybatis动态数据源及其原理
    UE4插件 - 编辑器工具栏按钮
    [LeetCode周赛复盘] 第 310 场周赛20220911
    Spring 中毒太深,模仿Spring
    mysql数据库重启、登录mysql数据库、通过命令执行mysql的sql脚本等命令
    【网络安全】如何保护IP地址?
    移动硬盘显示要格式化怎么办?
    mapper层传list集合,返回集合中不存在于表中的数据
    JAVA基础相关知识点(二)
  • 原文地址:https://blog.csdn.net/weixin_50645221/article/details/133131544