Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [CSS]zależne div-y rozwijalne
krzesik
post
Post #1





Grupa: Zarejestrowani
Postów: 517
Pomógł: 1
Dołączył: 25.08.2012

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


Witam,

mam dwa divy, które po naciśnięciu się rozwijają:

  1. <script type="text/javascript">
  2. function op1(obj) {
  3. x=document.getElementById(obj);
  4. $(x).slideToggle( "slow" );
  5. }
  6. <div style="margin: 5px 5px 5px 5px; border-radius: 5px; background-color: #009999; font-size:25px; color: yellow; font-weight: bold; padding: 25px 25px 25px 25px; cursor: pointer"
  7. onclick="op1('poka12')">Przypominajka
  8. <span class="glyphicon glyphicon-chevron-right" style="float:right;"></span></input>
  9. </div>
  10. <div style="display: none" id="poka12">
  11. <div id="poka12">
  12. .......
  13. </div>
  14. </div>
  15.  
  16. <script type="text/javascript">
  17. function op2(obj) {
  18. x=document.getElementById(obj);
  19. $(x).slideToggle( "slow" );
  20. }
  21. <div style="margin: 5px 5px 5px 5px; border-radius: 5px; background-color: #009999; font-size:25px; color: yellow; font-weight: bold; padding: 25px 25px 25px 25px; cursor: pointer"
  22. onclick="op2('poka11')">Przypominajka 2
  23. <span class="glyphicon glyphicon-chevron-right" style="float:right;"></span></input>
  24. </div>
  25. <div style="display: none" id="poka11">
  26. <div id="poka11">
  27. .......
  28. </div>
  29. </div>


jak zrobić, aby nie można było rozwinąć ich jednocześnie? Czyli jeden jest rozwinięty, rozwijając drugi zwija się pierwszy? Nie mogę sobie z tym poradzić.....

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Salvation
post
Post #2





Grupa: Zarejestrowani
Postów: 406
Pomógł: 73
Dołączył: 15.07.2014

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


HTML i CSS zostaje jak był. Poniżej JS, który tylko musisz przekleić (i dostosować pod siebie):
[JAVASCRIPT] pobierz, plaintext
  1. $(document)
  2. .find(".fake-button")
  3. .on("click", function () {
  4. const duration = "slow"
  5. const id = $(this).data("target");
  6. const $target = $(document).find(id)
  7. const $pokas = $(document).find(".poka").not(id)
  8.  
  9. $pokas.slideUp(duration)
  10. $target.is(":visible") ? $target.slideUp(duration) : $target.slideDown(duration)
  11. })
[JAVASCRIPT] pobierz, plaintext

Demo: https://jsfiddle.net/vp7xr6e8/1/
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 13.10.2025 - 12:55