简体   繁体   English

视差滚动(使用JavaScript)问题

[英]Parallax scrolling(using JavaScript) issue

I am trying to use parallax scrolling using JavaScript and Bootstrap. 我正在尝试使用JavaScript和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 您应该使用这样的css属性在图像周围添加环绕式div

HTML 的HTML

<div class="container">
  <img id="image" src="../images/company_img1.jpg" height="700px" width="100%" alt="companyProfile_image" class="img-responsive" />
</div>

CSS 的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. 这样,图像在移动时不会影响DOM的其余部分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM