Показать сообщение отдельно
  #13 (permalink)  
Старый 20.10.2013, 10:31
Аватар для BETEPAH
Профессор
Отправить личное сообщение для BETEPAH Посмотреть профиль Найти все сообщения от BETEPAH
 
Регистрация: 23.06.2011
Сообщений: 1,165

Переписал немного функцию, чтоб было понятнее
<!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>
Ответить с цитированием