Add resize event listener to regenerate spectrum

master
Guillaume Dott 2015-10-02 16:42:24 +02:00
parent 690368c118
commit ef9848b4ea
1 changed files with 9 additions and 0 deletions

View File

@ -86,6 +86,8 @@ WhatColorIsIt.prototype.spectrum = function(today) {
var tomorrow = today + 86400000; var tomorrow = today + 86400000;
var increment = (tomorrow - today) / this.spectrumDiv.offsetWidth; var increment = (tomorrow - today) / this.spectrumDiv.offsetWidth;
this.spectrumDiv.innerHTML = '';
for(var i = today; i < tomorrow; i += increment) { for(var i = today; i < tomorrow; i += increment) {
color = document.createElement('div'); color = document.createElement('div');
color.style.background = this.toColor(new Date(i)); color.style.background = this.toColor(new Date(i));
@ -117,6 +119,13 @@ WhatColorIsIt.prototype.process = function(d) {
WhatColorIsIt.prototype.run = function() { WhatColorIsIt.prototype.run = function() {
this.spectrum(Date.today()); 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(); this.start();
}; };
WhatColorIsIt.prototype.start = function() { WhatColorIsIt.prototype.start = function() {