anfil89 Posted June 19, 2012 at 09:58 PM Report Share #464250 Posted June 19, 2012 at 09:58 PM Boas, eu estou a desenvolver um projeto universitário e gostava de saber se alguém me pode resolver um problema... Eu tenho uma barra lateral com várias secções, e cada uma delas tem várias opções que têm a opção de estar visíveis ou não, e acontece que quando se abre a página elas estão visíveis, mas eu queria que estivessem escondidas e só ficariam visíveis quando se clica-se na secção correspondente. // this tells jquery to run the function below once the DOM is ready $(document).ready(function() { // choose text for the show/hide link - can contain HTML (e.g. an image) var showText= '<input type="image" src="../images/sidebar/arrow_show.png"/>'; var hideText= '<input type="image" src="../images/sidebar/arrow_hide.png"/>'; // initialise the visibility check //var is_visible = false; var check = false; // append show/hide links to the element directly preceding the element with a class of "toggle" $('.toggle').prev().append(' <a href="#" class="toggleLink">'+hideText+'</a>'); // hide all of the elements with a class of 'toggle' $('.toggle').show(); // capture clicks on the toggle links $('a.toggleLink').click(function() { // switch visibility //is_visible = !is_visible; // change the link text depending on whether the element is shown or hidden if (check) { check = false; $(this).html(hideText); $(this).parent().next('.toggle').slideDown('slow'); } else { check = true; $(this).html(showText); $(this).parent().next('.toggle').slideUp('slow'); } // return false so any link destination is not followed return false; }); }); Link to comment Share on other sites More sharing options...
dsimoes12 Posted June 29, 2012 at 12:55 PM Report Share #466422 Posted June 29, 2012 at 12:55 PM Se calhar já resolveste o problema mas parece-me que existem soluções mais elegantes e com menos código. O que precisas do JQuery é isto: http://api.jquery.com/toggle/ Penso no geral é o seguinte: definir no css ou através do jquery os submenus como não visiveis definir acção click (como estavas a fazer) que chama a função toggle() do JQuery é só! =) se precisares Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now