在页面滚动上调整页眉或缩小页眉的大小

时间:2017-07-11 08:47:17

标签: javascript jquery html css twitter-bootstrap-3

$(document).ready(function(){
	$(".l-right").click(function(){
	  debugger;
	  $(".menu-overlay").show();
	});
	$(".icon-close").click(function(){
	  debugger;
	  $(".menu-overlay").hide();
	});
});
.header-top {
	background: rgba(0, 47, 77, .3);
	height: 100px;
	padding: 0 10px;
	position: fixed;
	top: 0;
	width: 100%;
	z-index: 12;
	box-sizing: border-box;
}


.clearfix:before,
.clearfix:after {
  content: "";
  display: table;
}

.clearfix:after {
  clear: both;
}

.l-left {
	float: left;
}

.l-right {
	float: right;
}


.toggle-menu {
	width: 50px;
	height: 50px;
	display: inline-block;
	position: relative;
	top: -40px;
}

.toggle-menu i {
	position: absolute;
	display: block;
	height: 2px;
	background: white;
	width: 30px;
	left: 10px;
	-webkit-transition: all .3s;
	        transition: all .3s;
}

.toggle-menu i:nth-child(1) {
	top: 16px;
}

.toggle-menu i:nth-child(2) {
	top: 24px;
}

.toggle-menu i:nth-child(3) {
	top: 32px;
}

.icon-menu{
	color: #FFFFFF;
	font-size: 2.2em;
}
.menu-overlay {
	display: none;
    position: fixed;
    top: 0;
    z-index: 9999;
    height: 100%;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.65);
}
.menu-body{
	position: fixed;
    top: 0;
    z-index: 99999;
    right: 0;
    height: 100%;
	background-color: #ef4f51;
	width: 35%;
	float: right;
}
span.closer {
    font-size: 50px;
    float: right;
    color: white;
    padding: 30px;
}
.menu-pan{
    width: 100%;
    float: left;
    padding: 0 80px;
}
.menu-pan li {
	padding: 10px 0;
}
.menu-pan li a {
    color: white;
    text-decoration: none;
    font-size: 32px;
}
.btn-round{
	border-radius: 17px;
}
.btn {
    padding: 8px 25px;
    border: 0 none;    
    text-transform: uppercase;
    /* margin-left:10px; */
   /*  margin-right: 100px; */
    margin-top:35px;
    letter-spacing: 2px;
    font-size: 1em;
    font-family: 'Roboto', sans-serif;
}
.btn-danger {
    background: #ef4f50;
    color: #ffffff;
}
.btn-danger:hover, .btn-danger:focus, .btn-danger:active, .btn-danger.active, .open > .dropdown-toggle.btn-danger {
    background: #c03233;
}
.btn-danger:active, .btn-danger.active {
    background: #c03233;
    box-shadow: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" rel="stylesheet"/>

<header>
      <div class="header-top clearfix">
        <a href="https://www.google.co.in/" target="_blank" class="pull-right btn btn-danger btn-round  donate">DONATE NOW</a>
        <img src="http://safindia.org/assets/img/logohome.png" class="img-responsive" />
        <a class="l-right toggle-menu" href="#" id="pop">
          <span class="icon-menu" onclick="openNav()"></span>
        </a>
      </div>

      <div class="menu-overlay">
        <div class="menu-body">
          <a href="#"><span class="closer" onclick="closeNav()"><i class="icon-close icons"></i></span></a>
          <ul class="menu-pan">
            <li><a href="index.html">Home</a></li>
            <li><a href="about.html">About Us</a></li>
            <li><a href="whatwedo.html">What We Do</a></li>
            <li><a href="getinvolved.html">Get Involved</a></li>
            <li><a href="contactus.html">Contact Us</a></li>
          </ul>
        </div>
      </div>
    </header>

你好上面的代码是汉堡包侧面导航菜单我想让它缩小或调整页面滚动,我想从右侧打开菜单,平滑过渡效果&amp;当我点击外面打开的菜单(菜单 - 正文)时,它应该关闭。

1 个答案:

答案 0 :(得分:0)

见下面的工作代码。 为代码说明添加了注释

$(document).ready(function(){
	$(".l-right").click(function(){
	  debugger;
	  $(".menu-overlay").show();
	});
	$(".icon-close").click(function(){
	  debugger;
	  $(".menu-overlay").hide();
	});
  /** SCROLL **/
  $(window).scroll(function() {    
    var scroll = $(window).scrollTop();
     
    if (scroll >= 50) {
        //clearHeader, not clearheader - caps H
        $("header").addClass("sticky");
    }
    else{
      $("header").removeClass("sticky");       
    }
    /* You can adjust on scroll behaviour here */
});  
  
  
});
.header-top {
	background: rgba(0, 47, 77, .3);
	height: 100px;
	padding: 0 10px;
	position: fixed;
	top: 0;
	width: 100%;
	z-index: 12;
	box-sizing: border-box;
}


.clearfix:before,
.clearfix:after {
  content: "";
  display: table;
}

.clearfix:after {
  clear: both;
}

.l-left {
	float: left;
}

.l-right {
	float: right;
}


.toggle-menu {
	width: 50px;
	height: 50px;
	display: inline-block;
	position: relative;
	top: -40px;
}

.toggle-menu i {
	position: absolute;
	display: block;
	height: 2px;
	background: white;
	width: 30px;
	left: 10px;
	-webkit-transition: all .3s;
	        transition: all .3s;
}

.toggle-menu i:nth-child(1) {
	top: 16px;
}

.toggle-menu i:nth-child(2) {
	top: 24px;
}

.toggle-menu i:nth-child(3) {
	top: 32px;
}

.icon-menu{
	color: #FFFFFF;
	font-size: 2.2em;
}
.menu-overlay {
	display: none;
    position: fixed;
    top: 0;
    z-index: 9999;
    height: 100%;
    width: 100%;
    background-color: rgba(0, 0, 0, 0.65);
}
.menu-body{
	position: fixed;
    top: 0;
    z-index: 99999;
    right: 0;
    height: 100%;
	background-color: #ef4f51;
	width: 35%;
	float: right;
}
span.closer {
    font-size: 50px;
    float: right;
    color: white;
    padding: 30px;
}
.menu-pan{
    width: 100%;
    float: left;
    padding: 0 80px;
}
.menu-pan li {
	padding: 10px 0;
}
.menu-pan li a {
    color: white;
    text-decoration: none;
    font-size: 32px;
}
.btn-round{
	border-radius: 17px;
}
.btn {
    padding: 8px 25px;
    border: 0 none;    
    text-transform: uppercase;
    /* margin-left:10px; */
   /*  margin-right: 100px; */
    margin-top:35px;
    letter-spacing: 2px;
    font-size: 1em;
    font-family: 'Roboto', sans-serif;
}
.btn-danger {
    background: #ef4f50;
    color: #ffffff;
}
.btn-danger:hover, .btn-danger:focus, .btn-danger:active, .btn-danger.active, .open > .dropdown-toggle.btn-danger {
    background: #c03233;
}
.btn-danger:active, .btn-danger.active {
    background: #c03233;
    box-shadow: none;
}

.sticky .header-top{
  background: red;
  height:50px;  /*You can adjust sticky/shrinked menu and its child using .sticky class*/
}
.sticky .btn{
margin-top:10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/simple-line-icons/2.4.1/css/simple-line-icons.css" rel="stylesheet"/>

<header>
      <div class="header-top clearfix">
        <a href="https://www.google.co.in/" target="_blank" class="pull-right btn btn-danger btn-round  donate">DONATE NOW</a>
        <img src="http://safindia.org/assets/img/logohome.png" class="img-responsive" />
        <a class="l-right toggle-menu" href="#" id="pop">
          <span class="icon-menu" onclick="openNav()"></span>
        </a>
      </div>

      <div class="menu-overlay">
        <div class="menu-body">
          <a href="#"><span class="closer" onclick="closeNav()"><i class="icon-close icons"></i></span></a>
          <ul class="menu-pan">
            <li><a href="index.html">Home</a></li>
            <li><a href="about.html">About Us</a></li>
            <li><a href="whatwedo.html">What We Do</a></li>
            <li><a href="getinvolved.html">Get Involved</a></li>
            <li><a href="contactus.html">Contact Us</a></li>
          </ul>
        </div>
      </div>
    </header>

<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>
<p>
  Hello <br/> 
   Hello <br/> 
</p>