简体   繁体   English

如何根据背景更改汉堡菜单的颜色?

[英]How to change color of a burger menu depending on background?

On the page I have many sections:在页面上我有很多部分:

<section class="white"></section>
<section class="blue-gradient"></section>
<section class="white"></section>
<section class="blue-gradient"></section>
...

And I have fixed the burger menu.我已经修复了汉堡菜单。 I need to change color of the burger depending on background section when we scroll.滚动时,我需要根据背景部分更改汉堡的颜色。 When the burger on white section - the burger is blue, when the burger on blue section - the burger is white.当白色部分的汉堡 - 汉堡是蓝色的,当蓝色部分的汉堡 - 汉堡是白色的。

在此处输入图像描述

You can look at what section is currently visible and toggle the burger menu accordingly:您可以查看当前可见的部分并相应地切换汉堡菜单:

https://jsfiddle.net/3urpd60s/ https://jsfiddle.net/3urpd60s/

$(document).on("scroll",function(){

    var scrollTop = $(document).scrollTop(), 
        elems = $("section"),
        sections = elems.map((i,n)=> $(n).height()),
        tmp = -1, i = 0;

        while(tmp < scrollTop){
           tmp += sections[++i];
        }

    $('#burger').toggleClass("white", !$(elems[--i]).hasClass("white"));    

});

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

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