[英]Parallax scrolling(using JavaScript) issue
我正在尝试使用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';
?>
您应该使用这样的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的其余部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.