JSFiddle - React, Tailwind, and code Playground

by Tiago Agostinho

HTML

<body>
    <div id="linha"></div>

    <div id="fundoTopo">
        <div class="center">
            <div id="topo">
                <div class="logo">
                    <h1>TOPO DO SITE</h1>
                </div>
            </div>
        </div>
    </div>

    <div id="fundoMenu" class="normal">
        <div class="center">
            <div id="menu">
                <ul>
                    <li><a href="#">Home</a></li>
                    <li class="separador"></li>
                    <li><a href="#">Sobre</a></li>
                    <li class="separador"></li>
                    <li><a href="#">Fotos</a></li>
                    <li class="separador"></li>
                    <li><a href="#">Contato</a></li>
                </ul>
            </div>
        </div>
    </div>

    <div id="fundoBanner">
        <div class="center">
            <div id="banner">

            </div>
        </div>
    </div>

    <div id="fundoConteudo">
        <div class="center">
            <div id="conteudo">
                <h1>Lorem Ipsum</h1>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic...

CSS

*{
    margin: 0;
    padding: 0;
}
body{
    font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
    font-size: 98%;
    outline: none;
    color: #000;
}
ul li{
    list-style-type: none;
}
a{
    text-decoration: none;
    color: #000;
    font-size: 21px;
}
a:hover{
    background-color: #000;
    color: #FFF;
}

#linha{
    border: 4px solid #000;
}

.center{
    margin: 0 auto;
    position: relative;
    width: 1020px;
}
.clear{ clear: both; }

/*----------------------------
TOPO
-----------------------------*/
#fundoTopo{
    border-bottom: 1px solid #efefef;
}
#topo{
    height: 160px; /* altura do topo */
}
#topo .logo{ line-height: 160px; }

/*----------------------------
MENU
-----------------------------*/
#fundoMenu{}
#menu{
    height: 60px;
    width: 100%;
}
#menu ul li{
    display: inline;
    line-height: 60px;
}
#menu ul li.separador{
    border-left: 1px solid #efefef;
    height: 40px;
    margin: 0 10px;
    width: 1px;
}
#menu ul li a{
    padding: 5px 10px;
}
#menu ul li a:hover{
    border: 1px solid #000;
    border-radius: 6px;
}


.fixo {
    background-color: #000;
    height: 60px;
    position: fixed;
    top: 0;
    width: 100%;
    z-index: 100;
}
.fixo li a{ color: #FFF; }
.fixo li a:hover{
    background-color: #FFF;
    color: #000;
}

.normal{
    position: relative;
    width: 100%;
}
.normal li a{ color: #000; }
.normal li a:hover{
    background-color: #000;
    color: #FFF;
}

/*----------------------------
BANNER
-----------------------------*/
#banner{
    height: 280px;
    background-color: #efefef;
    border-radius: 10px;
    border: 1px solid #efefef;
    margin-bottom: 10px;
}

/*----------------------------
CONTEÚDO
-----------------------------*/
#fundoConteudo{
    background-color: #efefef;
}
#conteudo{
    padding: 20px 0;
    line-height: 1.8;
}
#conteudo h1{
    font-weight: normal;
    font-size: 28px;
}
#conteudo p{
    margin: 30px...

JavaScript

$(function(){
    var topo    = $('#fundoTopo'),
        posicao = topo.offset();
    $(window).scroll(function(){
        // quando rola barra de rolagem para baixo
        if($(this).scrollTop() > posicao.top+topo.height()){
            topo.stop().animate({ 'opacity':'0' },200, function(){
                // $(this).next() = pega próx. elemento (#fundoMenu)
                // .removeClass('normal') = remove css (.normal)
                // .addClass('fixo') = adiciona css (.fixo)
                $(this).next().removeClass('normal').addClass('fixo');
            });
            // quando retorna a barra de rolagem ao topo
        } else if($(this).scrollTop() <= posicao.top+topo.height()){
            topo.stop().animate({ 'opacity':'1' },80, function(){
                $(this).next().removeClass('fixo').addClass('normal');
            });
        }
    });
});