简体   繁体   English

固定背景和内容附件

[英]Fixed background and content attachment

Hey guys I have a fixed background attachment for scrolling uptill two pages of the content after that i want the second page to be fixed and make the third page with a different background to come up covering the second page.大家好,我有一个固定的背景附件,用于向上滚动直到内容的两页,然后我希望第二页被修复,并使第三页具有不同的背景以覆盖第二页。 How can I make the content of the second page fixed when it comes at the top?当第二页出现在顶部时,如何固定第二页的内容? So that scroll effect can be appliedm这样可以应用滚动效果

You have to use Javascript Intersection Observer API. Create an instance of it and set it to observe your 3rd page.您必须使用 Javascript Intersection Observer API。创建它的实例并将其设置为观察您的第 3 页。 On threshold crossing apply the styles you need (like setting position: relative; to both of your pages and then adjusting them via z-index).在阈值交叉处应用您需要的 styles(例如设置 position: relative; 到您的两个页面,然后通过 z-index 调整它们)。

Just don't unobserve() on collision so you can roll back changes on, well, scrolling up on your page.只是不要在碰撞时取消观察(),这样你就可以回滚更改,嗯,在你的页面上向上滚动。

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

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