Throw a collapse button through the menu

0

In the page I'm developing, the contents are all hidden by the bootstrap collapse class. As it is a Single Page, I would like my menu to go to your own section and then display the content without having to click the button.

I'll put an example here:

<nav id="menu">
  <ul>
    <li><a href="#item1">Item 1</a></li>
    <li>Item 2</li>
    <li>Item 3</li>
  </ul>
</nav>

<main>
<div class="container">
  <section id="item1">
    <a href="conteudo-item1" data-toggle="collapse">Saiba Mais</a>
    <div id="conteudo-item1" class="container collapse">
      Conteúdo...
    </div>
  </section>
</div>

I'm trying to do this using jQuery, but I'm not getting it. I have already used the click (), triggle () and triggleHandler () events.

    
asked by anonymous 05.07.2017 / 20:31

1 answer

0

I'm not sure I understand the right question, but I'll try to answer it.

$(document).scroll(function () {
    var scroll = $(this).scrollTop();
    $('conteudo-item1').each(function () {
        var offset = $(this).parent().offset().top;
        if (scroll > offset) {
            $(this).collapse('show');
        } else {
            $(this).collapse('hide');
        }
    });
});
    
13.07.2017 / 04:09