Огромное вам спасибо :victory:
|
Помогите добить скрипт.
Залил сюда:http://mw3.vn.ua/greenwave/traffic_lights.html Получилось синхронно обращаться к фазам светфора и к координатам. Но непонятно почему выкидывает ошибку. Мои новые наработки можно увидеть между 71й и 104й строкой |
Переписал немного функцию, чтоб было понятнее
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8" /> <style type="text/css"> span {padding-left:50px; width: 50px; height: 50px;} </style> <script src="http://code.jquery.com/jquery-latest.js"></script> <script type="text/javascript"> $(function() { traffic_lights = [ [{color:'green' ,time:9 }, {color:'yellow' ,time:6 }, {color:'red' ,time:19 },], [{color:'green' ,time:9 }, {color:'yellow' ,time:6 }, {color:'red' ,time:19 },], [{color:'green',time:30}, {color:'yellow',time:6}, {color:'red',time:17},], [{color:'green',time:30}, {color:'yellow',time:6}, {color:'red',time:17},], [{color:'red',time:29}, {color:'yellow',time:6}, {color:'red',time:27},], [{color:'red',time:29}, {color:'yellow',time:6}, {color:'red',time:27},], [{color:'green',time:32}, {color:'yellow',time:6}, {color:'red',time:40},], [{color:'green',time:32}, {color:'yellow',time:6}, {color:'red',time:40},], [{color:'green',time:37}, {color:'yellow',time:6}, {color:'red',time:33},], [{color:'green',time:37}, {color:'yellow',time:6}, {color:'red',time:33},], [{color:'red',time:23}, {color:'yellow',time:3}, {color:'green',time:80}, {color:'yellow',time:6},], [{color:'red',time:56}, {color:'yellow',time:3}, {color:'green',time:21}, {color:'yellow',time:6},], ] var traffic_locations = [ {x1:47,y1:63,x2:70,y2:84}, {x1:47,y1:103,x2:70,y2:124}, {x1:47,y1:194,x2:70,y2:215}, {x1:47,y1:234,x2:70,y2:255}, {x1:47,y1:363,x2:70,y2:384}, {x1:47,y1:403,x2:70,y2:424}, {x1:47,y1:578,x2:70,y2:599}, {x1:47,y1:618,x2:70,y2:639}, {x1:47,y1:709,x2:70,y2:730}, {x1:47,y1:749,x2:70,y2:770}, {x1:47,y1:878,x2:70,y2:899}, {x1:47,y1:918,x2:70,y2:939}, ] for (var a = 0, f; a < traffic_lights.length; a++) { var g = traffic_lights[a]; f = $("#c" + a); (function (el, colorsForThis, num) { var b = 0, time = 0; return function s() { if(!time) { var coord = traffic_locations[num];//перехожу к координатам светофоров var toWrite = ''; toWrite += '(' + num; //номер светофора toWrite += ' - ' + coord.x1 + '.' + coord.y1 + '.' + coord.x2 + '.' + coord.y2 + ' - '; //координаты toWrite += colorsForThis[b].color + ') '//цвет $('#log').html($('#log').html() + toWrite); el.css({"background-color": colorsForThis[b].color}); time = colorsForThis[b].time; b = ++b % colorsForThis.length; } el.html(time); time--; window.setTimeout(s, 1e3); } })(f, g, a)(); } }) </script> </head> <body> <span id="c0"></span> <span id="c1"></span><br><br> <span id="c2"></span> <span id="c3"></span><br><br> <span id="c4"></span> <span id="c5"></span><br><br> <span id="c6"></span> <span id="c7"></span><br><br> <span id="c8"></span> <span id="c9"></span><br><br> <span id="c10"></span> <span id="c11"></span> <div id="log"></div> </body> </html> |
Цитата:
у вас массив координат содержит массивы, в каждом из которых по одному элементу - объект с координатами. А надо чтоб массив содержал не массивы, а объекты. На пальцах: Вместо: [[{}],[{}],[{}],[{}]] надо [{},{},{},{}] Ну, или оставить как есть, но общаться соответствующе var tl = traffic_locations[a][0];//перехожу к координатам светофоров |
Часовой пояс GMT +3, время: 10:46. |