From ef9848b4ea10be68ce5fa756b3e9be7ca8dd69ea Mon Sep 17 00:00:00 2001 From: Guillaume Dott Date: Fri, 2 Oct 2015 16:42:24 +0200 Subject: [PATCH] Add resize event listener to regenerate spectrum --- index.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/index.html b/index.html index 09468be..7614074 100644 --- a/index.html +++ b/index.html @@ -86,6 +86,8 @@ WhatColorIsIt.prototype.spectrum = function(today) { var tomorrow = today + 86400000; var increment = (tomorrow - today) / this.spectrumDiv.offsetWidth; + this.spectrumDiv.innerHTML = ''; + for(var i = today; i < tomorrow; i += increment) { color = document.createElement('div'); color.style.background = this.toColor(new Date(i)); @@ -117,6 +119,13 @@ WhatColorIsIt.prototype.process = function(d) { WhatColorIsIt.prototype.run = function() { this.spectrum(Date.today()); + window.addEventListener('resize', function() { + if(typeof resizewait != 'undefined') { + clearTimeout(resizewait); + } + resizewait = setTimeout(function() { this.spectrum(Date.today()); }.bind(this), 200); + }.bind(this)); + this.start(); }; WhatColorIsIt.prototype.start = function() {