简体   繁体   English

如何创建可滚动的覆盖内容?

[英]How to create scrollable overlay content?

I'm trying to recreate the page of Hello Monday and I'm currently just adding the static content before adding the parallax effect and auto-scroll.我正在尝试重新创建Hello Monday的页面,目前我只是在添加视差效果和自动滚动之前添加静态内容。 This is what I have so far:这是我到目前为止:

Sandbox Link沙盒链接

One of the issues I'm running into is figuring out the best way to add the content in the overlay div and make it scrollable along with the background image.我遇到的问题之一是找出在叠加层 div 中添加内容并使其与背景图像一起滚动的最佳方法。 Should I place numerous divs at 100% height in the overlay?我应该在叠加层中以 100% 的高度放置多个divs吗? Not entirely sure what would be the best move here.不完全确定这里最好的举动是什么。

None of your "scrollable" divs should be scrollable you are going to need to get the wheel event on your body and from that you can basically paginate both parent sections, background and overlay.您的所有“可滚动”div 都不应该是可滚动的,您需要在身体上获取滚轮事件,然后您基本上可以对父部分、背景和叠加层进行分页。

All of the divs that will hold your content need to be 100% height or width of the parent depending on the direction of scroll.根据滚动方向,所有包含内容的 div 都需要是父级的 100% 高度或宽度。

document.addEventListener('mousewheel', (e) => {
  console.log(e.deltaY);
  // this will be the direction up or down
})

You will also need to keep track of the height of your parent containers, this is if the window is resized you can correctly figure out how many pixels it is until the next container.您还需要跟踪父容器的高度,这是如果调整窗口大小,您可以正确计算出下一个容器之前的像素数。

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

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