Jump to content
Guest MatheusT

Alguém poderia me ajudar a entender o código Jquery?

Recommended Posts

Guest MatheusT

Olá, eu estou começando a aprender Jquery, alguém poderia me explicar como funciona esse código abaixo?

$(function() {  
  menu = $('nav ul');

  $('#openup').on('click', function(e) {
    e.preventDefault();
    menu.slideToggle();
  });

  $(window).resize(function() {
    var w = $(this).width();
    if (w > 480 && menu.is(':hidden')) {
      menu.removeAttr('style');
    }
  });   

  $('nav li').on('click', function(e) {
    var w = $(window).width();
    if (w < 480) {
      menu.slideToggle();
    }
  });
  $('.open-menu').height($(window).height());
});

eu tenho a barra de menu em html

<header>
      <nav class='bar'>
        <ul class='bar'>
          <li class="screen-small">
            <a href="#showcase">Lorem Ipsum</a>
          </li>
          <li>
            <a href='#showcase'>Home</a>
          </li>
          <li>
            <a href='#music'>Music</a>
          </li>
          <li>
            <a href='#video'>Video</a>
          </li>
          <li>
            <a href='#premium'>Premium</a>
          </li>
        </ul>
        <a href='#' id='openup'>myTunes</a>
      </nav>
    </header>

 

Edited by MatheusT

Share this post


Link to post
Share on other sites
N3lson

1ª Função -> mostrar e esconder menu

2ª Função -> ao redimensionar janela, se o tamanho da mesma for maior que 480px e o menu estiver escondido, então remover o  style.css que indica para display: none ou algo do género

3ª Função se clicares no link do menu e se a janela for menor que 480 mostrar ou esconder (depende da situação)

4ª $('.open-menu').height($(window).height()); -> colocar o tamanho da div (menu) do mesmo tamanho da janela visível


You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.