Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> CSS i jQuery wariujące divy
przemysuaw
post
Post #1





Grupa: Zarejestrowani
Postów: 50
Pomógł: 0
Dołączył: 3.02.2013

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


Chce stworzyć 4 divy - kwadrat 2x2 divy.

Wszystko wygląda pięknie, ale jak odpalam zdarzenie hover, które powinno lekko poruszyć konkretnego diva to tylko, lewy górny zachowuje się zgodnie z oczekiwaniami, pozostałe szaleją po ekranie.

CSS:
  1. #zawartosc_index {
  2. margin-left:20%;
  3. position:absolute;
  4. }
  5. #ofirmie {
  6. position: relative;
  7. width: 300px;
  8. height:300px;
  9. border:20px solid white;
  10. background-color:#99CC00;
  11. color:white;
  12. float:left;
  13. }
  14. #panel_klienta {
  15. position: relative;
  16. border:20px solid white;
  17. width: 300px;
  18. height:300px;
  19. background-color:#33CCCC;
  20. float:right;
  21. color:white;
  22. }
  23. #oferta {
  24. position: relative;
  25. border:20px solid white;
  26. width: 300px;
  27. height:300px;
  28. background-color:#FF9900;
  29. float:left;
  30. color:white;
  31. }
  32. #kontakt {
  33. position: relative;
  34. border:20px solid white;
  35. width: 300px;
  36. height:300px;
  37. background-color:#CC99FF;
  38. float:left;
  39. color:white;
  40. }


HTML:
  1. <div id="zawartosc_index">
  2.  
  3. <div id="ofirmie">
  4. <h2 class="h2index">O firmie</h2>
  5. </div>
  6.  
  7. <div id="panel_klienta">
  8. <h2 class="h2index">Panel Klienta</h2>
  9. </div>
  10.  
  11. <div style="clear:both;"></div>
  12.  
  13. <div id="oferta">
  14. <h2 class="h2index">Oferta</h2>
  15. </div>
  16.  
  17.  
  18. <div id="kontakt">
  19. <h2 class="h2index">Kontakt</h2>
  20. </div>
  21.  
  22. </div>


i Jeszcze na koniec Jquery:
  1. $(document).ready(function(){
  2. // HOVER oferta
  3. var topo = $('#oferta').position().top;
  4. var lefto = $('#oferta').position().left;
  5.  
  6. $('#oferta').hover(function(){
  7. $(this).animate({top: $(this).position().top+10, left: $(this).position().left - 20},{duration: 200, queue: false});
  8. }, function(){
  9. $(this)
  10. .stop(true)
  11. .animate({top: topo, left: lefto},'fast');
  12. });
  13.  
  14. // HOVER O firmie
  15. var topf = $('#ofirmie').position().top;
  16. var leftf = $('#ofirmie').position().left;
  17.  
  18. $('#ofirmie').hover(function(){
  19. $(this).animate({top: $(this).position().top-10, left: $(this).position().left - 20},{duration: 200, queue: false});
  20. }, function(){
  21. $(this)
  22. .stop(true)
  23. .animate({top: topf, left: leftf},'fast');
  24. });
  25.  
  26. // HOVER panel klienta
  27. var topp = $('#panel_klienta').position().top;
  28. var leftp = $('#panel_klienta').position().left;
  29.  
  30. $('#panel_klienta').hover(function(){
  31. $(this).animate({top: $(this).position().top-10, left: $(this).position().left - 30},{duration: 200, queue: false});
  32. }, function(){
  33. $(this)
  34. .stop(true)
  35. .animate({top: topp, left: leftp},'fast');
  36. });
  37.  
  38. // HOVER kontakt
  39. var topk = $('#kontakt').position().top;
  40. var leftk = $('#kontakt').position().left;
  41.  
  42. $('#kontakt').hover(function(){
  43. $(this).animate({top: $(this).position().top+10, left: $(this).position().left + 30},{duration: 200, queue: false});
  44. }, function(){
  45. $(this)
  46. .stop(true)
  47. .animate({top: topk, left: leftk},'fast');
  48. });
  49. });
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: 24.08.2025 - 02:20