Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [jQuery] Podwójne zdarzenie
.rmvb's
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 26.09.2012

Ostrzeżenie: (0%)
-----


Witam.
Zastanawiam się, w jaki sposób mogę przypisać jakby dwie rzeczy do jednego elementu.
Pokażę kod i wytłumaczę co chcę osiągnąć
  1. $(document).ready(function(){
  2. $("#menu-open").addClass("on");
  3. var szerokosc = $(window).width();
  4. $(".on").click(
  5. function()
  6. {
  7. $(".grey-panel").animate({width:"+="+szerokosc+"px"},1000);
  8. $('nav ul').delay( 200 ).animate({top:"+=40px" },1000);
  9. $("#menu-open").addClass("off").removeClass("on");
  10. });
  11.  
  12. $(".off").click(
  13. function()
  14. {
  15. $('nav ul').animate({top:"-=40px" },1000);
  16. $(".grey-panel").delay( 200 ).animate({width:"-="+szerokosc+"px"},1000);
  17.  
  18. $("#menu-open").removeClass("off");
  19. $("#menu-open").addClass("on");
  20.  
  21. });
  22. });


Chciałbym aby za pośrednictwem jednego przycisku otwierać i zamykać menu.
  1. <a id="menu-open" class=""></a>
  2. <div class="grey-panel">
  3. <ul>
  4. <li>jeden</li>
  5. <li>dwa</li>
  6. <li>trzy</li>
  7. <li>cztery</li>
  8. </ul>
  9. </div>

Po każdej akcji kliknięcia chciałem zmieniać klasę, aby kolejne kliknięcie otwierało inne zdarzenie. W efekcie tego co mam aktualnie, otwiera się jedynie zdarzenie od klasy on..
W jaki sposób mógłbym rozwiązać mój problem ?

Ten post edytował .rmvb's 5.09.2013, 14:43:31
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
styryl
post
Post #2





Grupa: Zarejestrowani
Postów: 223
Pomógł: 27
Dołączył: 16.04.2008
Skąd: Bakutilu

Ostrzeżenie: (0%)
-----


Cytat(buliq @ 6.09.2013, 11:00:30 ) *
bo to nie było live()


Zobacz dokumentacje: "As of jQuery 1.7, the .live() method is deprecated. Use .on() to attach event handlers. Users of older versions of jQuery should use .delegate() in preference to .live()."
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 14.10.2025 - 03:47