简体   繁体   English

滚动经过特定的div后更改颜色

[英]Changing color after scrolling past specific div

I'm trying to achieve a certain change in one of my div's upon scrolling past another div. 我试图在滚动到另一个div时实现我的一个div的某种更改。 To explain, I wish to change the color of my hamburger menu from white to black upon scrolling past the header image. 为了说明,我希望在滚动经过标题图像时将汉堡菜单的颜色从白色更改为黑色。 I've tried to achieve this by changing the CSS after an X amount of pixels, but this approach produces different results based on the viewport size. 我尝试通过在X像素数量后更改CSS来实现此目的,但是这种方法会根据视口大小产生不同的结果。 As I'm aiming to have the effect remain the same across multiple devices, ie maintaining responsiveness, this isn't an option. 由于我的目标是在多个设备上保持相同的效果,即保持响应速度,因此这不是一个选择。

An example of what I'm trying to accomplish can be found here: 我要完成的任务的示例可在此处找到:

http://altcph.dk/ http://altcph.dk/

The espcially interesting part about this example is that when you place the menu icon on the exact dividing line between the header and the following div, the upperhalf remains white, whilst the bottom half already changes color. 关于此示例的特别有趣的部分是,当您将菜单图标放置在标题和下一个div之间的精确分隔线上时,上半部分保持白色,而下半部分已经改变了颜色。 I'd be especially interested in achieving this, but I am at an absolute loss on achieving this effect. 我对实现这一目标特别感兴趣,但是我对实现此效果完全不知所措。

The site you shared actually uses more than one menu. 您共享的站点实际上使用多个菜单。 The menu is positioned absolutely, once in the header (with the white color) and again outside of the header (in blue). 菜单的位置绝对正确,一次在标题(白色)中,再一次在标题外部(蓝色)中。 The header is stacked above the rest of the elements in the page (z-index: 3) so it covers up the blue menu. 标头堆叠在页面中其余元素的上方(z索引:3),因此它掩盖了蓝色菜单。 As the header scrolls up, the white menu below appears. 当标题向上滚动时,下面的白色菜单出现。

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

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