I am trying to use parallax scrolling using JavaScript and Bootstrap. It is working but the footer is also moving along with the scroll-able content and I want that the footer should be fixed at the bottom.
<?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';
?>
You should add a wrapping div around the image with the css properties like this
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;
}
This way the image won't affect the rest of the DOM when it's moved.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.