Could anyone help me with this script?

-3

Good to script:

$(document).ready(function(){

    $("#banner").css({"height":$(window).height() + "px"});

    var flag = false;
    var scroll;

    $(window).scroll(function(){
        scroll = $(window).scrollTop();

        if(scroll > 200){
            if(!flag){
                $("#logo").css({"margin-top": "-5px", "width": "50px","height":"50px"});
                $("nav").css({"color": "#fff"});
                $("ul").css({"color": "#000"});
                flag = true;
            }
        }else{
            if(flag){
                $("#logo").css({ "width": "80px","height":"80px"});
                $("ul").css({"color": "#000"});
                $("header").css({"background-color": "#fff"});
                flag = false;
            }
        }


    });

});

html part of nav:

<header class="header">
        <nav>
            <ul>
                <a href="http://www.keyquotes.es"><li>Youtube</li></a>
                <a href="http://www.keyquotes.es"><li>Nosotros</li></a>
                <a href="http://www.keyquotes.es"><li>Contacto</li></a>
            </ul>

                <img id="logo" src="pictures/logo.png">

            <ul>
                <a href="http://www.keyquotes.es"><li>Youtube</li></a>
                <a href="http://www.keyquotes.es"><li>Nosotros</li></a>
                <a href="http://www.keyquotes.es"><li>Contacto</li></a>
            </ul>
        </nav>

</header>

I wanted to understand what's missing or where I'm going wrong, my intention with this script is that when the page is in the top the ul stay black img:

andwhenscrollingthescrollitbecomeswhitelikeimg:

  

AndthenIaddedthistothescript:$("ul"). css ({"color": "# 000"}); and   $ ("ul"). css ({"color": "#fff"}); , and what was the best option?

    
asked by anonymous 04.01.2018 / 14:00

1 answer

1

Let's go, you do not need this flag and the correct one to change the color is $("nav ul a")

  $(window).scroll(function(){
    scroll = $(window).scrollTop();
    if(scroll > 200){
            $("#logo").css({"margin-top": "-5px", "width": "50px","height":"50px"});
            $("nav ul a").css({"color": "blue"});                
            $("header").css({"background-color": "#fff"});
    }else{
            $("#logo").css({ "width": "80px","height":"80px"});
            $("nav ul a").css({"color": "#fff"});
            $("header").css({"background-color": "#000"});

    }

});

link

    
04.01.2018 / 16:10