Div Element就像一个背景

时间:2016-10-22 10:01:21

标签: javascript jquery html css

如何让<div>元素像背景一样充当此网络jabarprov.go.id

这是我的代码 http://codepen.io/anon/pen/RGEmxB

$(document).ready(function(){
    	   $(window).bind('scroll', function() {
    	   var navHeight = $( window ).height() - 70;
    			 if ($(window).scrollTop() > navHeight) {
    				 $('nav').addClass('fixed');
    			 }
    			 else {
    				 $('nav').removeClass('fixed');
    			 }
    		});
    	});
#div1, #div2{
    			height:100vh;
    		}
    		
    		#div1{background-color:cyan}
    		#div2{background-color:lightgrey}
    		
    		nav {
    			position: absolute;
    			bottom: 0;
    			width: 100%;
    			background: Green;
    			padding:2px 0;
    			z-index:1;
    		}
    		
    		.fixed {
    			position: fixed; 
    			top: 0; 
    			height: 70px; 
    			z-index: 1;
    		}
    		section {
    			height: 100vh;
    		}

    		/* Screens Settings */
    		#screen1 {	
    			background: #43b29d;
    		}

    		#screen1 p {
    			padding-top: 200px;
    		}

    		#screen2 {
    			background: #efc94d;
    		}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>



    <div id="div1" class="col-md-3">LEFT SECTION</div>
        <div id="div2" class="col-md-9">RIGHT SECTION</div>
    	<nav class="main-bg">
    	    <div class="container">
    			NAVIGATION HERE
    		</div>
    	</nav>
    	<section id="screen2"></section>
    	<section id="screen3"></section>

问题是介绍我的页面没有修复(就像固定背景一样)。

1 个答案:

答案 0 :(得分:1)

我修改了你的代码。 希望这是你搜索的内容 http://codepen.io/anon/pen/qaLGrp

我在div1和2周围做了一个包装,它被修复并改成大小

包装

<div id="intro-wrapper">
  <div id="div1" class="col-md-3">a</div>
  <div id="div2" class="col-md-9">b</div>
</div>

包装器css和尺寸

body{
  padding-top: 100vh;
}
#intro-wrapper{
  z-index: -1;
  position: fixed;
  top: 0;
  width: 100vw;
}
#div1, #div2{
  height:calc(100vh - 70px);
}

导航位置

nav {
  position: absolute;
  top: calc(100vh - 70px);
  width: 100%;
  background: Green;
  padding:2px 0;
  z-index:1;
  height:70px;
}