javascript - 如何显示一个固定的 Div 在底部后面的另一个 Div 显示像视差一样滚动

标签 javascript css

如何像视差一样在滚动时显示一个固定的 div 在另一个 Div 后面的底部显示

https://jsfiddle.net/wa6b645e/

<div class="div_1">
<h1>DIV One</h1>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</p>

<p>..more content here..</p>
</div>

<div class="div_2">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</p>
</div>

当滚动 div_1 时,像视差一样显示底部的 div_2(此 div 固定在底部)。 请帮我找到解决方案。

最佳答案

您可以使用纯 CSS 来完成。我创建了自己的示例,我认为其他人会更清楚:

html {
  height: 100%;
}

body {
  height: 100%;
  margin: 0;
}

.main {
  position: relative;
  z-index: 1;
  background-color: #999;
  overflow: hidden;
  height: 100%;
  margin-bottom: 200px;
}

footer {
  height: 200px;
  width: 100%;
  background-color: #333;
  overflow: hidden;
  position: fixed;
  bottom: 0;
}

重要的是补充

position: relative;

到主分区。并为 .main margin-bottom 和 footer height 设置相同的值。或者至少不小。

这是一个工作示例:http://codepen.io/paweljanicki/pen/YGWGEx

关于javascript - 如何显示一个固定的 Div 在底部后面的另一个 Div 显示像视差一样滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39530998/

相关文章:

html - 在后台以纯 css3 制作垂直分隔器

javascript - JavaScript 不调用函数

javascript - Vue - 如何覆盖包装器组件的 Prop ?

javascript - 如何检索 html CDATA 部分中的文本?

javascript - 从数组中的字符串中删除数字

html - 将 li 元素包含在导航栏中

css - 居中还是不居中?

html - 如何以绝对位置在右侧放置一个div

javascript - 似乎无法让 babel 和 webpack 为 ES2015 工作,出现导入错误

javascript - iOS 浏览器 : For a overlay like a pop up menu 100vh does not work correctly and gets hidden under the 44px pixel high menu bar of safari