Last active
December 28, 2017 10:04
-
-
Save YonatanKra/6126680fc83ce59e37bd0f4f95afdc9e to your computer and use it in GitHub Desktop.
Fireworks added to the mix
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
import template from './index.html'; | |
import {} from './app.css'; | |
import YOPFForm from './form/form.index'; | |
import YOPFFireworks from './fireworks/fireworks.index'; | |
(function() { | |
function onPhraseChange(phrase) { | |
fireworks.doFireworks(phrase); | |
} | |
document.body.innerHTML = template; | |
const form = new YOPFForm(document.getElementById('phrase-form-wrapper')); | |
const fireworks = new YOPFFireworks(document.getElementById('phrase-fireworks-wrapper')); | |
form.listen(onPhraseChange); | |
})(); |
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
.phraseText { | |
position: relative; | |
top: 50%; | |
transform: translateY(-50%); | |
text-align: center; | |
} |
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
const fireworks = require('fireworks'); | |
// get the styles | |
import {} from './fireworks.css'; | |
class YOPFFireworks{ | |
constructor(element) { | |
this._element = element; | |
} | |
get centerX() { | |
return this._centerX ? this._centerX : this._centerX = this._element.offsetLeft + this._element.offsetWidth / 2; | |
} | |
get centerY() { | |
return this._centerY ? this._centerY : this._centerY = this._element.offsetTop + this._element.offsetHeight / 2; | |
} | |
doFireworks(phrase) { | |
this._element.innerHTML = '<h1 class="phraseText">' + phrase + '</h1>'; | |
if (this._interval) { | |
return; | |
} | |
this._interval = setInterval(() => { | |
const newX = Math.random()*100*(Math.random() < .5 ? -1 : 1); | |
const newY = Math.random()*100*(Math.random() < .5 ? -1 : 1); | |
fireworks({ | |
x: this.centerX + newX, | |
y: this.centerY + newY, | |
colors: ["#cc3333", "#4CAF50", "#81C784"] | |
}); | |
}, 500); | |
} | |
stopFireworks() { | |
if (!this._interval) { | |
return; | |
} | |
clearInterval(this._interval); | |
this._interval = null; | |
} | |
} | |
export default YOPFFireworks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment