Last active
December 14, 2015 09:09
-
-
Save smessing/5062870 to your computer and use it in GitHub Desktop.
A working example for the DTSE JavaScript lecture. The HTML document defines a 5 x 5 table. The JS code iterates row-by-row, changing the color of each cell in turn.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
font-family: 'Arial'; | |
font-size: 46px; | |
text-align: center; | |
} | |
.centered { | |
margin: 0 auto; | |
padding-top: 60px; | |
width: 600px; | |
} | |
table { | |
border: 1px solid black; | |
width: 100%; | |
} | |
td, tr { | |
padding: 10px; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" type="text/css" href="table_color.css"> | |
<script src="table_color.js"></script> | |
</head> | |
<body onload="main()"> | |
<div class="centered"> | |
<table> | |
<tr> | |
<td id="1-1">1-1</td> | |
<td id="1-2">1-2</td> | |
<td id="1-3">1-3</td> | |
<td id="1-4">1-4</td> | |
<td id="1-5">1-5</td> | |
</tr> | |
<tr> | |
<td id="2-1">2-1</td> | |
<td id="2-2">2-2</td> | |
<td id="2-3">2-3</td> | |
<td id="2-4">2-4</td> | |
<td id="2-5">2-5</td> | |
</tr> | |
<tr> | |
<td id="3-1">3-1</td> | |
<td id="3-2">3-2</td> | |
<td id="3-3">3-3</td> | |
<td id="3-4">3-4</td> | |
<td id="3-5">3-5</td> | |
</tr> | |
<tr> | |
<td id="4-1">4-1</td> | |
<td id="4-2">4-2</td> | |
<td id="4-3">4-3</td> | |
<td id="4-4">4-4</td> | |
<td id="4-5">4-5</td> | |
</tr> | |
<tr> | |
<td id="5-1">5-1</td> | |
<td id="5-2">5-2</td> | |
<td id="5-3">5-3</td> | |
<td id="5-4">5-4</td> | |
<td id="5-5">5-5</td> | |
</tr> | |
</table> | |
</div> <!-- .centered --> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var main = function() { | |
var color_tile = function(i, j, delay) { | |
var cell_id = String(i) + "-" + String(j); | |
var cell_element = document.getElementById(cell_id); | |
console.log("Processing cell: " + cell_id); | |
var style = function() { | |
cell_element.style.backgroundColor = "#da0002"; | |
}; | |
setTimeout(style, delay * 100); | |
}; | |
var delay = 1; | |
for (var i = 1; i < 6; i++) { | |
for (var j = 1; j < 6; j++) { | |
color_tile(i, j, delay); | |
delay += 1; | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment