Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [JavaScript]Piwo (naprawdę) za rozwiązanie problemu
Forum PHP.pl > Forum > Przedszkole
swmikolaj21
Witam,

Mam pilny problem do rozwiązania, treść poniżej. Dla osoby, która poda rozwiązanie problemu i wyjaśni jego przyczyny stawiam piwo! Prawdziwe, nie wirtualne, przeleję 10 złoty (myślę, że wystarczy nawet na dwa), a osoba potwierdzi na forum, że otrzymała $$ i spija właśnie piwko.... smile.gif


Pomóżcie proszę:

Bardzo słabo rozumiem JS, a mam taki problem z galerią, która działa tylko w FF. Po rozpoczęciu przeglądania zdjęć od danego zdjęcia z ustalonym id nie działają pliki następny, poprzedni itp.
oto strona: http://latayachts.pl/galeria.php?id=21

Wydaje mi się, że jest jakiś problem z przekazaniem ID zdjęcia (gdy brak parametru id wszystko jest OK)

Oto problematyczny kod:
  1. var gallery6 = [
  2. "img/full/foto34.jpg",
  3. "img/full/foto33.jpg",
  4. "img/full/foto32.jpg",
  5. "img/full/foto0711.jpg",
  6. "img/full/foto0705.jpg",
  7.  
  8. ];
  9.  
  10.  
  11. var galleries = [gallery1, gallery2, gallery3, gallery4, gallery5, gallery6,];
  12. var gallery = null;
  13. var galleryIdx = null;
  14. var slideInterval = null;
  15. var langID = "pl";
  16.  
  17. function GalleryImageID() {
  18. if (galleryIdx == null)
  19. return "0705";
  20. var img = gallery[galleryIdx];
  21. if (typeof img == "object")
  22. img = img.src;
  23. return img.replace(/^.*\/img\/full\/foto(.+)\.jpg$/, "$1");
  24. }
  25.  
  26. function GalleryInit() {
  27. var curImg = document.getElementById("CurrentImage");
  28. var curName = curImg.src;
  29.  
  30. curName = curName.substr(curName.lastIndexOf("/") + 1);
  31. for (var j = 0; j < galleries.length && galleryIdx == null; ++j) {
  32. gallery = galleries[j];
  33. for (var i = 0; i < gallery.length; ++i)
  34. if (gallery[i].indexOf(curName) >= 0) {
  35. galleryIdx = i;
  36. gallery[i] = new Image();
  37. gallery[i].src = curImg.src;
  38. break;
  39. }
  40. }
  41. if (gallery.length == 1) {
  42. document.getElementById("guzik_lewy").disabled = true;
  43. document.getElementById("guzik_prawy").disabled = true;
  44. document.getElementById("panel_lewo").disabled = true;
  45. document.getElementById("panel_slajdy").disabled = true;
  46. document.getElementById("panel_czas").disabled = true;
  47. document.getElementById("panel_prawo").disabled = true;
  48. }
  49. GalleryPreload();
  50. }
  51.  
  52. function GalleryNext() {
  53. if (galleryIdx != null) {
  54. var i = galleryIdx + 1;
  55. if (i >= gallery.length)
  56. i = 0;
  57. GallerySelect(i);
  58. }
  59. }


Będę wdzięczny za wszelką pomoc
Cezar708
wklej cały kod bo brakuje dość sporej części, na przykład funkcji GallerySelect oraz var gallery1-gallery5,

Pozdrawiam
swmikolaj21
Cały plik galeria.js:

  1. var gallery1 = [
  2.  
  3.  
  4. "img/full/foto1.jpg",
  5. "img/full/foto1532.jpg",
  6. "img/full/foto1533.jpg",
  7. "img/full/foto1401.jpg",
  8. "img/full/foto1477.jpg",
  9.  
  10.  
  11. ];
  12. var gallery2 = [
  13. "img/full/foto0712.jpg",
  14. "img/full/foto1391.jpg",
  15. "img/full/foto1395.jpg",
  16. "img/full/foto1513.jpg",
  17. "img/full/foto41.jpg",
  18. "img/full/foto1905.jpg",
  19. "img/full/foto1673.jpg",
  20. "img/full/foto1919.jpg",
  21. "img/full/foto1928.jpg",
  22. "img/full/foto2201.jpg",
  23. "img/full/foto2215.jpg",
  24. "img/full/foto1974.jpg",
  25.  
  26.  
  27.  
  28.  
  29.  
  30. ];
  31. var gallery3 = [
  32. "img/full/foto2570.jpg",
  33. "img/full/foto2574.jpg",
  34. "img/full/foto2557.jpg",
  35. "img/full/foto2632.jpg",
  36. "img/full/foto2601.jpg",
  37. "img/full/foto2604.jpg",
  38. "img/full/foto2629.jpg",
  39. ];
  40.  
  41. var gallery4 = [
  42. "img/full/foto21.jpg",
  43. "img/full/foto22.jpg",
  44. "img/full/foto23.jpg",
  45. "img/full/foto24.jpg",
  46. "img/full/foto25.jpg",
  47. "img/full/foto26.jpg",
  48. "img/full/foto27.jpg",
  49. "img/full/foto28.jpg",
  50. "img/full/foto0702.jpg",
  51. "img/full/foto0703.jpg",
  52. "img/full/foto0707.jpg",
  53. "img/full/foto0709.jpg",
  54.  
  55. ];
  56. var gallery5 = [
  57. "img/full/foto0162.jpg",
  58. "img/full/foto0163.jpg",
  59. "img/full/foto0166.jpg",
  60. "img/full/foto0296.jpg",
  61. "img/full/foto0308.jpg",
  62. "img/full/foto0314.jpg",
  63. "img/full/foto0319.jpg",
  64. "img/full/foto0296.jpg",
  65. "img/full/foto0319.jpg",
  66. "img/full/foto0421.jpg",
  67. "img/full/foto0422.jpg",
  68. "img/full/foto0423.jpg",
  69. "img/full/foto0424.jpg",
  70. "img/full/foto0425.jpg",
  71. "img/full/foto0426.jpg",
  72. "img/full/foto0427.jpg"
  73. ];
  74.  
  75. var gallery6 = [
  76. "img/full/foto34.jpg",
  77. "img/full/foto33.jpg",
  78. "img/full/foto32.jpg",
  79. "img/full/foto0711.jpg",
  80. "img/full/foto0705.jpg",
  81.  
  82. ];
  83.  
  84.  
  85. var galleries = [gallery1, gallery2, gallery3, gallery4, gallery5, gallery6,];
  86. var gallery = null;
  87. var galleryIdx = null;
  88. var slideInterval = null;
  89. var langID = "pl";
  90.  
  91. function GalleryImageID() {
  92. if (galleryIdx == null)
  93. return "0705";
  94. var img = gallery[galleryIdx];
  95. if (typeof img == "object")
  96. img = img.src;
  97. return img.replace(/^.*\/img\/full\/foto(.+)\.jpg$/, "$1");
  98. }
  99.  
  100. function GalleryInit() {
  101. var curImg = document.getElementById("CurrentImage");
  102. var curName = curImg.src;
  103.  
  104. curName = curName.substr(curName.lastIndexOf("/") + 1);
  105. for (var j = 0; j < galleries.length && galleryIdx == null; ++j) {
  106. gallery = galleries[j];
  107. for (var i = 0; i < gallery.length; ++i)
  108. if (gallery[i].indexOf(curName) >= 0) {
  109. galleryIdx = i;
  110. gallery[i] = new Image();
  111. gallery[i].src = curImg.src;
  112. break;
  113. }
  114. }
  115. if (gallery.length == 1) {
  116. document.getElementById("guzik_lewy").disabled = true;
  117. document.getElementById("guzik_prawy").disabled = true;
  118. document.getElementById("panel_lewo").disabled = true;
  119. document.getElementById("panel_slajdy").disabled = true;
  120. document.getElementById("panel_czas").disabled = true;
  121. document.getElementById("panel_prawo").disabled = true;
  122. }
  123. GalleryPreload();
  124. }
  125.  
  126. function GalleryNext() {
  127. if (galleryIdx != null) {
  128. var i = galleryIdx + 1;
  129. if (i >= gallery.length)
  130. i = 0;
  131. GallerySelect(i);
  132. }
  133. }
  134.  
  135. function GalleryPreload() {
  136. if (galleryIdx != null) {
  137. var lastIdx = gallery.length - 1;
  138. var i = galleryIdx == lastIdx? 0 : galleryIdx + 1;
  139. var img = new Image();
  140.  
  141. img.onload = GallerySetPreload;
  142. if (typeof gallery[i] == "string") {
  143. img.src = gallery[i];
  144. gallery[i] = img;
  145. }
  146. else {
  147. i = galleryIdx == 0? lastIdx : galleryIdx - 1;
  148. if (typeof gallery[i] == "string") {
  149. img.src = gallery[i];
  150. gallery[i] = img;
  151. }
  152. else {
  153. var stopIdx = i;
  154. i = galleryIdx + 2;
  155. if (i > lastIdx)
  156. i -= lastIdx + 1;
  157. for (; i != stopIdx; i = i >= lastIdx? 0 : i + 1)
  158. if (typeof gallery[i] == "string") {
  159. img.src = gallery[i];
  160. gallery[i] = img;
  161. break;
  162. }
  163. }
  164. }
  165. }
  166. }
  167.  
  168. function GalleryPrev() {
  169. if (galleryIdx != null) {
  170. var i = (galleryIdx == 0? gallery.length : galleryIdx) - 1;
  171. GallerySelect(i);
  172. }
  173. }
  174.  
  175. function GalleryRunSlideshow() {
  176. if (slideInterval == null) {
  177. var msecs = parseInt(document.getElementById("panel_czas").value) * 1000;
  178. slideInterval = window.setInterval("GalleryNext()", msecs);
  179. document.getElementById("panel_slajdy").value = "Stop";
  180. }
  181. else
  182. GalleryStopSlideshow();
  183. }
  184.  
  185. function GallerySelect(idx) {
  186. var img = document.getElementById("CurrentImage");
  187. if (typeof gallery[idx] == "object")
  188. img.src = gallery[idx].src;
  189. else {
  190. var newImg = new Image();
  191. img.src = newImg.src = gallery[idx];
  192. gallery[idx] = newImg;
  193. }
  194. galleryIdx = idx;
  195. }
  196.  
  197. function GallerySetInterval() {
  198. if (slideInterval != null) {
  199. GalleryStopSlideshow();
  200. GalleryRunSlideshow();
  201. }
  202. }
  203.  
  204. function GallerySetLanguage(lang) {
  205. if (lang == "pl" || lang == "en" || lang == "de")
  206. langID = lang;
  207. }
  208.  
  209. function GallerySetPreload() {
  210. window.setTimeout("GalleryPreload()", 100);
  211. }
  212.  
  213. function GalleryStopSlideshow() {
  214. if (slideInterval != null) {
  215. window.clearTimeout(slideInterval);
  216. slideInterval = null;
  217. document.getElementById("panel_slajdy").value =
  218. langID == "pl"? "Slajdy" : "Slideshow";
  219. }
  220. }
l0ud
Kod
"img/full/foto1477.jpg",


];


Po ostatnim elemencie tablicy nie powinno być przecinka smile.gif Zdaje się, że IE interpretuje wtedy jedno jej pole jako puste i skrypt się wykłada przy wcztytywaniu. Pousuwaj wszędzie na końcu przecinki np.:
Kod
"img/full/foto1477.jpg"


];
swmikolaj21
Tak, to był ten błąd smile.gif Wielkie dzięki.

Podaj mi proszę na priv nr konta i zaraz przesyłam $$ na piwko smile.gif
l0ud
Oj, daj już spokój winksmiley.jpg Satysfakcja z udzielenia pomocy wystarcza.
Pozdrawiam
swmikolaj21
smile.gif To może kiedyś w realu spijemy, co? Świdwin to moje rodzinne miasto i czasem tam bywam smile.gif

Pozdrawiam i jeszcze raz wielkie dzięki!
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.