Skip to content

Instantly share code, notes, and snippets.

@YonatanKra
Last active December 28, 2017 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YonatanKra/6126680fc83ce59e37bd0f4f95afdc9e to your computer and use it in GitHub Desktop.
Save YonatanKra/6126680fc83ce59e37bd0f4f95afdc9e to your computer and use it in GitHub Desktop.
Fireworks added to the mix
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);
})();
.phraseText {
position: relative;
top: 50%;
transform: translateY(-50%);
text-align: center;
}
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