반복 타이머 만들기



							var x = 0;
							var timerID = setInterval(moveElement, 1000);

							function moveElement() {
								x += 10;
								if (x == 100) {
									clearInterval(timerID);
								}
								var left = x + "px";
								document.getElementById('redbox').style.left = left;
							}						
						


							var intervalId = null;

							window.onload = function () {
								console.log("onload!!");
								document.getElementById('redbox').onclick = stopStartElement;
							}

							function stopStartElement() {
								console.log("click");
								if (intervalId == null) {
									var x = 0;
									intervalId = setInterval(function () {
										x += 5;
										var left = x + "px";
										document.getElementById("redbox").style.left = left;
									}, 100);
								}else {
									clearInterval(intervalId);
									intervalId = null;
								}
							}							
						


							var intervalId = null;

							window.onload = function () {
								console.log("onload!!");
								var x = 0;
								document.getElementById('redbox').onclick = function () {
									if (intervalId == null) {
										intervalId = setInterval(function () {
											x += 5;
											var left = x + "px";
											document.getElementById("redbox").style.left = left;
										}, 100);
									}else {
										clearInterval(intervalId);
										intervalId = null;
									}
								}
							}