Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: setInterval pomocy
Forum PHP.pl > Forum > Po stronie przeglądarki > JavaScript
bartek6949
Funkcja niechce sie powtarzac co okreslony czas
oto kod
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
  6.  
  7. <script src="jquery-1.3.2.min.js" type="text/javascript"></script>
  8.  
  9. <script type="text/javascript">
  10.  
  11.  
  12.  
  13.  
  14.  
  15. $(document).ready(function() {
  16.  
  17. function gonie(i)
  18. {
  19.  
  20. var char = $("#character").position();
  21.  
  22. var char2 = $("#"+i+"").position();
  23.  
  24.  
  25. if(char.left<char2.left)
  26. {
  27. setTimeout(function() {
  28. $("#"+i+"").css({ backgroundPosition: "-70px 0px", left: char2.left - 3 });
  29. }, 40);//szybkosc
  30.  
  31. setTimeout(function() {
  32. $("#"+i+"").css({ backgroundPosition: "-35px 0px", left: char2.left - 6 });
  33. }, 80);//szybkosc
  34.  
  35. setTimeout(function() {
  36. $("#"+i+"").css({ backgroundPosition: "0px 0px", left: char2.left - 9 });
  37. }, 120);//szybkosc
  38.  
  39. }
  40. else if(char.left>char2.left)
  41. {
  42. setTimeout(function() {
  43. $("#"+i+"").css({ backgroundPosition: "-70px -70px", left: char2.left + 3 });
  44. }, 40);//szybkosc
  45. setTimeout(function() {
  46. $("#"+i+"").css({ backgroundPosition: "-35px -70px", left: char2.left + 6 });
  47. }, 80);//szybkosc
  48. setTimeout(function() {
  49. $("#"+i+"").css({ backgroundPosition: "0px -70px", left: char2.left + 9 });
  50. }, 120);//szybkosc
  51.  
  52.  
  53. }
  54. if(char.top<char2.top)
  55. {
  56. setTimeout(function() {
  57. $("#"+i+"").css({ backgroundPosition: "-70px -35px", top: char2.top - 3 });
  58. }, 40);
  59.  
  60. setTimeout(function() {
  61. $("#"+i+"").css({ backgroundPosition: "-35px -35px", top: char2.top - 6 });
  62. }, 80);
  63.  
  64. setTimeout(function() {
  65. $("#"+i+"").css({ backgroundPosition: "0px -35px", top: char2.top - 9 });
  66. }, 120);
  67.  
  68. }
  69. else if(char.top>char2.top)
  70. {
  71. setTimeout(function() {
  72. $("#"+i+"").css({ backgroundPosition: "-70px -105px", top: char2.top + 3 });
  73. }, 40);
  74.  
  75. setTimeout(function() {
  76. $("#"+i+"").css({ backgroundPosition: "-35px -105px", top: char2.top + 6 });
  77. }, 80);
  78.  
  79. setTimeout(function() {
  80. $("#"+i+"").css({ backgroundPosition: "0px -105px", top: char2.top + 9 });
  81. }, 120);//szybkosc
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88. }
  89.  
  90. setInterval("gonie('character2')",240);
  91.  
  92.  
  93.  
  94.  
  95. $(".health div").animate({ width: 25 }, 1000);
  96. $(".health2 div").animate({ width: 25 }, 1000);
  97. var last_walk = 0;
  98.  
  99.  
  100.  
  101. $("html").keydown(function(e) {
  102. if (new Date().getTime() - last_walk < 300) {//predkosc
  103. return true;
  104. }
  105.  
  106. var char = $("#character").position();
  107.  
  108.  
  109.  
  110. if (e.keyCode == 37) {
  111.  
  112. setTimeout(function() {
  113. $("#character").css({ backgroundPosition: "-70px 0px", left: char.left - 3 });
  114. }, 100);//szybkosc
  115.  
  116. setTimeout(function() {
  117. $("#character").css({ backgroundPosition: "-35px 0px", left: char.left - 6 });
  118. }, 200);//szybkosc
  119.  
  120. setTimeout(function() {
  121. $("#character").css({ backgroundPosition: "0px 0px", left: char.left - 9 });
  122. }, 300);//szybkosc
  123.  
  124. }
  125. else if (e.keyCode == 38) {
  126. setTimeout(function() {
  127. $("#character").css({ backgroundPosition: "-70px -35px", top: char.top - 3 });
  128. }, 100);
  129.  
  130. setTimeout(function() {
  131. $("#character").css({ backgroundPosition: "-35px -35px", top: char.top - 6 });
  132. }, 200);
  133.  
  134. setTimeout(function() {
  135. $("#character").css({ backgroundPosition: "0px -35px", top: char.top - 9 });
  136. }, 300);
  137. } else if (e.keyCode == 39) {
  138. setTimeout(function() {
  139. $("#character").css({ backgroundPosition: "-70px -70px", left: char.left + 3 });
  140. }, 100);
  141.  
  142. setTimeout(function() {
  143. $("#character").css({ backgroundPosition: "-35px -70px", left: char.left + 6 });
  144. }, 200);
  145.  
  146. setTimeout(function() {
  147. $("#character").css({ backgroundPosition: "0px -70px", left: char.left + 9 });
  148. }, 300);
  149. } else if (e.keyCode == 40) {
  150. setTimeout(function() {
  151. $("#character").css({ backgroundPosition: "-70px -105px", top: char.top + 3 });
  152. }, 100);
  153.  
  154. setTimeout(function() {
  155. $("#character").css({ backgroundPosition: "-35px -105px", top: char.top + 6 });
  156. }, 200);
  157.  
  158. setTimeout(function() {
  159. $("#character").css({ backgroundPosition: "0px -105px", top: char.top + 9 });
  160. }, 300);
  161. }
  162.  
  163.  
  164.  
  165. if (char.left <= 0) {
  166. setTimeout(function() {
  167. $("#character").css({ backgroundPosition: "0px 0px", left: char.left + 800 });
  168. $("#a").css({ background:"url(bg.jpg)"});
  169. }, 300);//szybkosc
  170. }
  171. last_walk = new Date().getTime();
  172. });
  173. });
  174. </script>
  175. <script type="text/javascript">
  176.  
  177. </script>
  178.  
  179.  
  180. <style type="text/css">
  181.  
  182. #a
  183. {
  184. background: transparent url(bg2.jpg) no-repeat;
  185. width: 600px;
  186. height: 450px;
  187. padding:0px;
  188. }
  189.  
  190.  
  191.  
  192. #character {
  193. background: transparent url(assassin.png) no-repeat;
  194. height: 35px;
  195. left: 36px;
  196. top: 18px;
  197. position: absolute;
  198. width: 35px;
  199.  
  200.  
  201. }
  202. #character2 {
  203. background: transparent url(assassin.png) no-repeat;
  204. height: 35px;
  205. left: 180px;
  206. top: 18px;
  207. position: absolute;
  208. width: 35px;
  209.  
  210.  
  211. }
  212. #character .health {
  213. background-color: #060;
  214. border: 1px solid #060;
  215. height: 2px;
  216. margin: -7px auto 0 auto;
  217. width: 25px;
  218. }
  219.  
  220. #character .health div {
  221. background-color: #6F0;
  222. height: 2px;
  223. width: 1px;
  224. }
  225. #character2 .health2 {
  226. background-color: #060;
  227. border: 1px solid #060;
  228. height: 2px;
  229. margin: -7px auto 0 auto;
  230. width: 25px;
  231. }
  232.  
  233. #character2 .health2 div {
  234. background-color: #6F0;
  235. height: 2px;
  236. width: 1px;
  237. }
  238. </style>
  239.  
  240. <title>Magnus</title>
  241.  
  242. </head>
  243.  
  244. <body>
  245. <div id="a">
  246.  
  247. <div id="character">
  248. <div class="health"><div>ja</div></div>
  249.  
  250.  
  251. </div>
  252. <div id="character2">
  253. <div class="health2"><div>bot</div></div>
  254.  
  255.  
  256. </div>
  257. </div>
  258. </body>
  259. </html>
nospor
a jaki to ma związek z ajaxem? No żaden.... przenosze
bartek6949
sam juz to zrobilem
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.