zoukankan      html  css  js  c++  java
  • jq实现吸顶菜单

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <style>
            body{
                padding: 0;
                margin: 0;
            }
            .fixed {
                position: fixed;
                top: 0;
                 100%;
                transition: .3s;
            }
        </style>
    
    </head>
    
    <body>
        <div style="height: 1500px;position: relative;">
            <div style="height: 80px;"></div>
            <div id="head" style="height: 120px;background-color: #000;"></div>
        </div>
        <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
        <script>
            $(document).scroll(function () {
                if ($(window).scrollTop() >= 80) {
                    if (!$("#head").hasClass("fixed")) {
                        $("#head").addClass("fixed")
                    }
                } else if ($("#head").hasClass("fixed")){
                    $("#head").removeClass("fixed")
                }
            });
        </script>
    </body>
    
    </html>

    参考:

    https://www.cnblogs.com/zhaoyingjie/p/6088358.html

    https://www.w3school.com.cn/jquery/attributes_removeclass.asp

    https://www.jb51.net/article/146887.htm

    https://blog.csdn.net/qq_29207823/article/details/81565160

  • 相关阅读:
    第一个gulp程序
    r.js打包
    吃饭途中的回忆
    IE下script标签的readyState属性
    CSS 选择器
    html的base标签
    迷你MVVM框架 avalonjs 1.3.9发布
    2014年的年终总结
    Visual Studio2017 数据库架构比较
    MVC开发中自定义返回类型
  • 原文地址:https://www.cnblogs.com/xiaqiuchu/p/14223476.html
Copyright © 2011-2022 走看看