Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.30 KB | None | 0 0
  1. #pojemnik1
  2. {
  3. position: relative;
  4. width: 1000px;
  5. margin: auto;
  6. }
  7. #nawigacja
  8. {
  9. margin-top: 1px;
  10. padding: 5px;
  11. }
  12. #nawigacja div img
  13. {
  14. width: 30px;
  15. min-height: 30px;
  16. }
  17. #nawigacja div:first-child
  18. {
  19. position: absolute;
  20. left: 35px;
  21. }
  22. #nawigacja div:last-child
  23. {
  24. position: absolute;
  25. right: 0px;
  26. }
  27. #pojemnik2
  28. {
  29. text-align: center;
  30. margin-top: 50px;
  31. min-height: 500px;
  32. }
  33. #pojemnik2 p
  34. {
  35. position: absolute;
  36. width: 100%;
  37. }
  38. #pojemnik2 img
  39. {
  40. height: 100px;
  41. max-width: 150px;
  42. margin: auto;
  43. }
  44. #pojemnik2 div
  45. {
  46. position: relative;
  47. border: 3px dotted;
  48. float: left;
  49. width: 200px;
  50. min-height: 250px;
  51. margin-right: 25px;
  52. margin-left: 25px;
  53. margin-bottom: 50px;
  54. left: 125px;
  55. }
  56. #pojemnik2 div input
  57. {
  58. position: absolute;
  59. left: 0px;
  60. bottom: 115px;
  61. width: 100%;
  62. background-color: grey;
  63. }
  64. table
  65. {
  66. position: relative;
  67. margin: auto;
  68. background-color: grey;
  69. border: 3px solid black;
  70. }
  71. table input
  72. {
  73. background-color: transparent;
  74. }
  75.  
  76. <!DOCTYPE html>
  77. <html>
  78. <head>
  79. <title>Sklep</title>
  80. <meta charset="UTF-8">
  81. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  82.  
  83. <script src="jquery-3.2.1.min.js"></script>
  84. <script>
  85. var stos = 0;
  86. var towary = new Array();
  87. var koszyk = new Array();
  88.  
  89. function towar(id, nazwa, cena, zdjecie, kategoria, podkategoria)
  90. {
  91. this.id = id;
  92. this.nazwa = nazwa;
  93. this.cena = cena;
  94. this.zdjecie = zdjecie;
  95. this.kategoria = kategoria;
  96. this.podkategoria = podkategoria;
  97.  
  98. stos++;
  99.  
  100. this.pokaz = function()
  101. {
  102. var html = "<div>" + '<img src="zdj/';
  103.  
  104. html += zdjecie + '"><hr><p>' + "<b>";
  105. html += this.nazwa + "</b><br>Cena: ";
  106. html += this.cena + "zł </p><input type='button' value='Kup Teraz' onclick='dodaj(";
  107. html += this.id + ")'></div>";
  108.  
  109. return html;
  110. };
  111. }
  112. function zakupy(id)
  113. {
  114. this.id = id;
  115. this.ilosc = 1;
  116. }
  117. function dodaj(id)
  118. {
  119. for(var i = 0; i < koszyk.length; i++)
  120. {
  121. if (koszyk[i].id == towary[id].id)
  122. {
  123. koszyk[i].ilosc++;
  124. }
  125. }
  126.  
  127. koszyk.push(new zakupy(id));
  128. }
  129. function zmien(id, zm)
  130. {
  131. for(var i = 0; i < koszyk.length; i++)
  132. {
  133. if (koszyk[i].id == towary[id].id)
  134. {
  135. koszyk[i].ilosc = $(zm).val();
  136.  
  137. if(koszyk[i].ilosc <= 0)
  138. koszyk.splice(i, 1);
  139. }
  140. }
  141.  
  142. wozek();
  143. }
  144. function usun(i)
  145. {
  146. koszyk.splice(i, 1);
  147. wozek();
  148. }
  149. function wyswietl()
  150. {
  151. var html = "";
  152.  
  153. for(var i = 0; i < towary.length; i++)
  154. {
  155. html += towary[i].pokaz();
  156. }
  157.  
  158. html += "";
  159.  
  160. $("#pojemnik2").html(html);
  161. }
  162. function wozek()
  163. {
  164. var wynik = 0;
  165. var html = "<table border=1><tr><td>LP.</td><td>Nazwa</td><td>Cena</td><td>Ilość</td><td>Razem</td><td>Cofnij</td></tr>";
  166.  
  167. for(var i = 0; i < koszyk.length; i++)
  168. {
  169. html += "<tr><td>" + i + "</td><td>";
  170. html += towary[koszyk[i].id].nazwa + "</td><td>";
  171. html += towary[koszyk[i].id].cena + " zł</td><td><input type='number' id='b";
  172. html += i + "' onchange='zmien(" + koszyk[i].id + ",b" + i + ")' value=" + koszyk[i].ilosc + "></td><td>";
  173. html += koszyk[i].ilosc * towary[koszyk[i].id].cena + " zł</td><td><input type='button' onclick='usun(" + i + ")' value='Usuń'></td></tr>";
  174. wynik += koszyk[i].ilosc * towary[koszyk[i].id].cena;
  175. }
  176.  
  177. html += "<tr><td colspan='6'>RAZEM:\t" + wynik + " zł</td></tr></table>"
  178. $("#pojemnik2").html(html);
  179. }
  180. $(document).ready(function()
  181. {
  182. wyswietl();
  183.  
  184. $("#nawigacja").children().first().click(function()
  185. {
  186. wyswietl();
  187. });
  188. $("#nawigacja").children().last().click(function()
  189. {
  190. wozek();
  191. });
  192. });
  193.  
  194. towary.push(new towar(stos, "Pamięć ADATA XPG DDR4 8GB/2400Mhz CL16", 397.75, "0.png", "RAM", "DDR4"));
  195. towary.push(new towar(stos, "Pamięć Ballistix DDR4 Sport LT 8GB(2*4GB)/2400Mhz", 359.00, "1.jpg", "RAM", "DDR4"));
  196. towary.push(new towar(stos, "Pamięć Corsair Vengeance LPX DDR4 8GB(2*4GB)/3000MHz CL15", 452.54, "2.jpg", "RAM", "DDR4"));
  197. towary.push(new towar(stos, "Pamięć HyperX FURY DDR3 8GB(2*4GB)/1600MHz CL10", 299.00, "3.jpg", "RAM", "DDR3"));
  198. towary.push(new towar(stos, "Pamięć Patriot Viper 4 DDR4 8GB(2*4GB)/3000MHz CL16", 434.51, "4.jpg", "RAM", "DDR4"));
  199. towary.push(new towar(stos, "Pamięć GoodRam IRDM DDR4 8GB/2400MHz CL15", 357.00, "5.jpg", "RAM", "DDR4"));
  200. </script>
  201.  
  202. <link rel="stylesheet" type="text/css" href="style.css">
  203. </head>
  204. <body background="zdj/tlo.jpg">
  205. <div id="pojemnik1">
  206. <div id="nawigacja">
  207. <div><img src="zdj/home.jpg">Strona domowa</div>
  208. <div><img src="zdj/koszyk.jpg">Przejdź do koszyka</div>
  209. </div>
  210. <div id="pojemnik2"></div>
  211. </div>
  212. </body>
  213. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement