我正在尝试使用JavaScript和Bootstrap进行视差滚动。它正在工作,但页脚也随着滚动内容一起移动,我希望页脚应该固定在底部。
<?php
require 'header.php';
?>
<style type="text/css">
*{
margin: 0px;
padding: 0px;
}
#image {
position: relative;
z-index: -1
}
#content {
position: relative;
z-index: 1;
height: 750px;
width: 100%;
background-color: #4dbbac;
margin-bottom: 30px
}
</style>
<script type="text/javascript">
var yPos, image;
function parallax (){
yPos = window.pageYOffset;
image = document.getElementById('image');
image.style.top = yPos * 1 + 'px';
}
window.addEventListener('scroll', parallax);
</script>
<img id="image" src="../images/company_img1.jpg" height="700px" width="100%" alt="companyProfile_image" class="img-responsive"/>
<div id="content"></div>
<?php
require 'footer.php';
?>
答案 0 :(得分:0)
您应该使用css属性(如
)在图像周围添加包装div<强> HTML 强>
<div class="container">
<img id="image" src="../images/company_img1.jpg" height="700px" width="100%" alt="companyProfile_image" class="img-responsive" />
</div>
<强> CSS 强>
.container {
position: relative;
z-index: 1;
overflow: hidden;
}
这样,图像在移动时不会影响其余的DOM。