导航固定头部 跟着页面走 js代码

二级导航菜单 导航栏 滑动导航 下拉导航 展开收缩 下拉导航菜单 下拉菜单导航 网址导航 二级导航 导航菜单插件 树形导航 收缩菜单 侧边导航 固定导航 导航切换

话不多说 上代码

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
    }
    
    .box {
        height: 2000px;
    }
    
    #wrap {
        background-color: rgba(0, 0, 0, 0.2);
        width: 100%;
        height: 100px;
    }
    
    #wrap[data-fixed="fixed"] {
        position: fixed;
        top: 0;
        left: 0;
        margin: 0;
    }
    
    .content {
        height: 2000px;
    }
    
    p {
        height: 500px;
    }
</style>


<body>
    <div class="box">
        <p>
            <div id="wrap"></div>
        </p>
        <div class="content">
            hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world
            hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello
            world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world
            hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world
            hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world
            hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello
            worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello world hello world hello world hello worldhello world hello worldhello world hello worldhello
            world hello world hello world hello worldhello world
        </div>
    </div>

</body>

<script>
    var obj = document.getElementById("wrap");
    var ot = obj.offsetTop;
    document.onscroll = function() {
        var st = document.body.scrollTop || document.documentElement.scrollTop;
        obj.setAttribute("data-fixed", st >= ot ? "fixed" : "")

    }
</script>

</html>

女同学们纷纷表示,这年头不找个程序员老公,还真是连节日低价购物权都没了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值