Browser Back button does not work to vote for DIV

Asked

Viewed 38 times

0

I have the code below.

When I’m at Home and click on the Menu to appear, for example, Projects and then press the back button of the browser, it doesn’t work. The url even changes, but the page does not go back to the previous div, in the case of Home.

<script type="text/javascript">


    function esconderDivs(){
        //Esconder Divs
        $('#projetos').hide();
        $('#lojaVirtual').hide();
        $('#quemSomosNos').hide();


        //Evento para deslizar o scroll e mostrar a div Início quando clica no Menu
        $('nav li:nth-child(1)').click(function(e){
            $('#projetos').hide();
            $('#lojaVirtual').hide();
            $('#quemSomosNos').hide();
            $('#meio').show();
                $('html, body').animate({scrollTop: $('#meio').offset().top}, 1000);

            })


        //Evento para deslizar o scroll e mostrar a div Projetos quando clica no Menu
        $('nav li:nth-child(2)').click(function(e){
            $('#meio').hide();
            $('#lojaVirtual').hide();
            $('#quemSomosNos').hide();
            $('#projetos').show();
                $('html, body').animate({scrollTop: $('#projetos').offset().top}, 1000);
            })


        //Evento para deslizar o scroll e mostrar a div Loja Virtual quando clica no Menu
        $('nav li:nth-child(3)').click(function(e){
            $('#meio').hide();
            $('#lojaVirtual').show();
            $('#quemSomosNos').hide();
            $('#projetos').hide();
                $('html, body').animate({scrollTop: $('#lojaVirtual').offset().top}, 1000);
            })

        //Evento para deslizar o scroll e mostrar a div Quem Somos Nós quando clica no Menu
        $('nav li:nth-child(5)').click(function(e){
            $('#meio').hide();
            $('#lojaVirtual').hide();
            $('#quemSomosNos').show();
            $('#projetos').hide();
                $('html, body').animate({scrollTop: $('#quemSomosNos').offset().top}, 1000);
            })
    }


    $(function(e){

        esconderDivs();

        $('#demo').carousel({
          interval: 7000
        });


        })

</script>

<?php include_once("_template/topo.php"); ?>        

<main>


    <!-- Sessão Início-->

    <section id="meio"> 

        <?php include("paginas/inicio.php") ?>


    </section> 


            <!-- Sessão Projetos-->
    <section id="projetos"> 

        <?php include("paginas/projetos.php") ?>

    </section>




    <!-- Sessão Loja Virtual-->

    <section id="lojaVirtual"> 

        <?php include("paginas/lojaVirtual.php") ?>


    </section>



    <section id="quemSomosNos"> 

            <?php include("paginas/quemSomosNos.php") ?>

    </section>


        <!-- Rodapé da página-->

        <?php include_once("_template/rodape.php"); ?>  


        <script src="src/js/bootstrap.min.js"></script>
        <script src="src/js/jquery-3.3.1.js"></script>


</main>

  • Reverse the call of scripts, because jQuery has to be the first script to be called on the page, always. You know what it is for (and) that you have declared within various functions??

  • Inverti, but nothing has changed.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.