diff options
Diffstat (limited to 'projects/1-colour-shift/main.js')
-rw-r--r-- | projects/1-colour-shift/main.js | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/projects/1-colour-shift/main.js b/projects/1-colour-shift/main.js index 53a5d4f..8fc7609 100644 --- a/projects/1-colour-shift/main.js +++ b/projects/1-colour-shift/main.js @@ -9,17 +9,22 @@ function computeRgb(x, y, width, height) { // This will be an array of nodes since we are // using class name (array may have length 0 or 1) let attentionNodes +// Make sure we wait until the page is ready. +// Querying the DOM before the page is ready +// will result in queries returning null/empty array window.onload = function() { - document.getElementsByClassName('attention') + attentionNodes = document.getElementsByClassName('attention') } document.onmousemove = function(event) { - // iterate over each node and update its style + // calculate the color once (will be used + // for all nodes) let color = computeRgb( event.pageX, event.pageY, window.innerWidth, window.innerHeight ) + // iterate over each node and update its style for (let node of attentionNodes) { node.style.color = color } |