html鼠标滚动后导航栏吸顶效果

html鼠标滚动后导航栏吸顶效果

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>html鼠标滚动后导航栏吸顶效果</title>
<style>
* {
    padding: 0;
    margin: 0
}
ul, li {
    list-style: none;
}
a {
    text-decoration: none;
    color: #333;
}
.content {
     1200px;
    margin: auto;
}
.menu {
    line-height: 60px;
    height: 60px;
}
.menu li {
    float: left;
    padding: 0 15px;
}
.sticky {
    position: fixed;
    height: auto;
    z-index: 10000;
    background-color: #2778af;
     100%;
    top: 0px;
    background-color: rgba(30, 30, 30, 0.94);
    border-bottom: none;
    padding: 0;
    -webkit-transition: all 0.5s ease-in-out;
    -moz-transition: all 0.5s ease-in-out;
    -ms-transition: all 0.5s ease-in-out;
    -o-transition: all 0.5s ease-in-out;
    transition: all 0.5s ease-in-out;
}
.sticky a {
    color: #fff;
}
.banner{
	height: 100vh; /*banner高度一屏幕*/
	background: pink;
}
.con {
	height: 5000px;
}

</style>
<script src="https://cdn.bootcss.com/jquery/2.1.0/jquery.js"></script> 
<script>
	$(window).scroll(function() {
        var wScroll = $(this).scrollTop();
        if (wScroll > 0) {
            $('.menu-box').addClass('sticky');
        } else {
            $('.menu-box').removeClass('sticky');
        }
    });	
</script>
</head>
<body>
<div class="menu-box">
  <div class="content">
    <ul class="menu">
      <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>
  </div>
</div>
<div class="banner">
</div>
<div class="con"></div>
</body>
</html>


原文地址:https://www.cnblogs.com/xaun/p/13740809.html