Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Onclick = menu podjeżdża, js na jquery
mambus
post 1.08.2012, 14:26:15
Post #1





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 30.11.2010

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


Witajcie.
Zwracam się do Was z pewną prośbą, mianowicie: mam pewien skrypt w JS który działa w taki sposób, że po kliknięciu w np linka, od razu mi otwiera schowaną w div-ie zawartość. Działa to dobrze, ale chciałbym w pewien sposób go zmodyfikować - docelowo ma to działać tak że po kliknięciu ten div będzie jechał do góry a nie pojawiał się od razu.

Za pewne będzie trzeba to zrobić w jquery. Niestety nie mam zielonego pojęcia jak to zrobić. Znalazłem kilka rozwiązań w internecie ale żadne nie odpowiada mojemu ani metodologia jaką zostały wykonane.

Skrypt poniżej.

  1. function openClose(id)
  2. {
  3. if(document.getElementById) {
  4. element = document.getElementById(id);
  5. } else if(document.all) {
  6. element = document.all[id];
  7. } else return;
  8.  
  9. if(element.style) {
  10. if(element.style.display == 'block' ){
  11. element.style.display = 'none';
  12. } else {
  13. element.style.display = 'block';
  14. }
  15. }
  16. }


Czy ktoś mógłby mi pomóc ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 9)
ukaszf9
post 1.08.2012, 19:45:40
Post #2





Grupa: Zarejestrowani
Postów: 33
Pomógł: 3
Dołączył: 23.10.2011

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


  1. <script>
  2. $('#click').click(function() {
  3. $('#top').show('slow');
  4. });
  5. </script>
  6.  
  7. <a href="#" id="click">click</a>
  8. <div id="top" style="display:none;">TOP</div>

Chodzi o coś takiego czy ten div ma lecieć do góry ekranu wybranego miejsca?

Ten post edytował ukaszf9 1.08.2012, 19:46:26
Go to the top of the page
+Quote Post
mambus
post 1.08.2012, 23:01:43
Post #3





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 30.11.2010

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


tak, ma lecieć do góry ekranu. Niestety nie działa to co kolega podał.

EDIT: Udało mi się. Wygooglowałem sobie tę funkcję show w jquery. Tylko problem jest w tym że div wjeżdża od lewej a chciałbym żeby wjeżdżał od góry - da się to zmodyfikować ?

Ten post edytował mambus 1.08.2012, 23:49:50
Go to the top of the page
+Quote Post
ukaszf9
post 2.08.2012, 09:36:27
Post #4





Grupa: Zarejestrowani
Postów: 33
Pomógł: 3
Dołączył: 23.10.2011

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


Podaj co wklejasz.
Go to the top of the page
+Quote Post
mambus
post 2.08.2012, 10:22:56
Post #5





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 30.11.2010

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


  1. <script>
  2. $("#showit").click(function () {
  3. $("#menu_before2").hide("slow");
  4. $("#container").show("slow");
  5.  
  6. });
  7. </script>


tutaj chyba się to modyfikuje ?
Go to the top of the page
+Quote Post
ethann
post 2.08.2012, 10:48:11
Post #6





Grupa: Zarejestrowani
Postów: 56
Pomógł: 18
Dołączył: 7.04.2012

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


Z użyciem jQuery.

  1. <!doctype html>
  2. <meta charset="UTF-8" />
  3. <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
  4. <script type="text/javascript">
  5. $(function() {
  6. $("dl#menu dt").click(function() {
  7. $(this).nextAll().slideToggle('fast');
  8. });
  9. });
  10. </script>
  11. <style type="text/css">
  12. dl#menu {margin:0; float:left; border:2px solid #333;}
  13. dl#menu dt {width:120px; height:25px; display:block; background-color:#666; color:#fff; font-weight:bold; text-align:center; cursor:pointer;}
  14. dl#menu dd {width:120px; height:25px; display:block; background-color:#aaa; color:#fff; font-weight:bold; text-align:center; margin:0; padding:0; display:none;}
  15. </style>
  16.  
  17. <dl id="menu">
  18. <dt>Nawigacja</dt>
  19. <dd>Strona główna</dd>
  20. <dd>Chat</dd>
  21. <dd>Artykuły</dd>
  22. <dd>Linki</dd>
  23. </dl>
  24.  
  25. <dl id="menu">
  26. <dt>Nawigacja #2</dt>
  27. <dd>Strona główna</dd>
  28. <dd>Chat</dd>
  29. <dd>Artykuły</dd>
  30. <dd>Linki</dd>
  31. </dl>
  32.  
  33. <dl id="menu">
  34. <dt>Nawigacja #3</dt>
  35. <dd>Strona główna</dd>
  36. <dd>Chat</dd>
  37. <dd>Artykuły</dd>
  38. <dd>Linki</dd>
  39. </dl>
  40.  
  41. </body></html>


Ten post edytował ethann 2.08.2012, 10:49:35
Go to the top of the page
+Quote Post
mambus
post 3.08.2012, 12:20:15
Post #7





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 30.11.2010

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


wszystko okej - ale nie zrozumieliśmy się. Takie rozwiązanie już znalazłem, w przypadku jaki kolega podał, menu rozwija się do dołu, a ja chciałbym żeby rozwijało się do góry, stąd też pytałem czy może nie da się zmienić gdzieś kierunku rozwijania w jquery, nie widziałem by funkcje ani slide, ani show miały możliwość nadawania kierunków od których miały by "jechać".
Go to the top of the page
+Quote Post
ukaszf9
post 3.08.2012, 12:32:33
Post #8





Grupa: Zarejestrowani
Postów: 33
Pomógł: 3
Dołączył: 23.10.2011

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


Trzeba było od razu tak napisać smile.gif od tego jest funkcja slideUp();
- http://api.jquery.com/slideUp/
Go to the top of the page
+Quote Post
mambus
post 3.08.2012, 12:34:55
Post #9





Grupa: Zarejestrowani
Postów: 53
Pomógł: 0
Dołączył: 30.11.2010

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


A właśnie nie - bo slideUP chowa.
Ale udało mi się znaleźć bardzo podobne rozwiązanie do tego co chcę - jedyna różnica że podjeżdża kawałek, a ja chce żeby do samej góry podlatywało.

http://atomicrobotdesign.com/blog/web-deve...rom-the-bottom/
Go to the top of the page
+Quote Post
ethann
post 3.08.2012, 15:32:42
Post #10





Grupa: Zarejestrowani
Postów: 56
Pomógł: 18
Dołączył: 7.04.2012

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


Zmodyfikowany kod z przykładu podanego przez Ciebie.
  1. <!DOCTYPE html>
  2. <meta charset="utf-8" />
  3. <title>toggleSlide Up</title>
  4. html, body {
  5. height:100%;
  6. }
  7. body {
  8. padding:0;
  9. margin:0;
  10. background:#000;
  11. font-family:Arial, Helvetica, sans-serif;
  12. }
  13. .container {
  14. width:960px;
  15. height:100%;
  16. margin:0 auto;
  17. position:relative;
  18. }
  19. .about_popup {
  20. width:360px;
  21. height:100%;
  22. padding:0 20px;
  23. background:#333;
  24. position:absolute;
  25. left:0;
  26. bottom:0;
  27. display:none;
  28. -moz-border-radius-topleft:20px;
  29. -moz-border-radius-topright:20px;
  30. -webkit-border-top-left-radius:20px;
  31. -webkit-border-top-right-radius:20px;
  32. }
  33. .about_popup h1 {
  34. color:#fff;
  35. margin:0;
  36. font-size:20px;
  37. }
  38. .about_popup p {
  39. margin:0;
  40. color:#fff;
  41. }
  42. .bottom_bar {
  43. width:100%;
  44. height:40px;
  45. background:#333;
  46. background:-moz-linear-gradient(#333,#000);
  47. background:-webkit-gradient(linear, left top, left bottom, from(#333), to(#000));
  48. box-shadow:-4px 0 4px #111;
  49. position:absolute;
  50. bottom:0;
  51. }
  52. .bottom_bar ul {
  53. list-style:none;
  54. width:960px;
  55. margin:0 auto;
  56. }
  57. .bottom_bar ul li {
  58. float:left;
  59. line-height:40px;
  60. }
  61. .bottom_bar ul li a {
  62. color:#fff;
  63. text-decoration:none;
  64. margin-right:20px;
  65. }
  66. a {
  67. text-decoration:none;
  68. font-family:helvetica, arial, sans-serif;
  69. color:#000;
  70. }
  71. </style>
  72. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
  73. $(function() {
  74. $('#bottom_menu a').click(function() {
  75. var elem = $($(this).attr('href') + '_popup');
  76.  
  77. $('div.container div').not(elem).slideUp();
  78. elem.slideToggle();
  79. });
  80. });
  81. </script>
  82. </head>
  83.  
  84. <div class="container">
  85. <div id="about_popup" class="about_popup">
  86. <h1>About</h1>
  87. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.</p>
  88. </div>
  89. <div id="info_popup" class="about_popup">
  90. <h1>Info</h1>
  91. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.</p>
  92. </div>
  93. <div id="else_popup" class="about_popup">
  94. <h1>Else</h1>
  95. <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper.</p>
  96. </div>
  97. </div>
  98. <div class="bottom_bar">
  99. <ul id="bottom_menu">
  100. <li><a href="#about">About</a></li>
  101. <li><a href="#info">Info</a></li>
  102. <li><a href="#else">Else</a></li>
  103. </ul>
  104. </div>
  105. </body>
  106. </html>
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 04:56