JSFiddle - React, Tailwind, and code Playground
by magikMaker
HTML
<div class="notification-modal">
<canvas id="confetti"></canvas>
<span class="close-button">X</span>
<div class="notification-content ">
<h1 class="title">Gefeliciteerd</h1>
<p class="tag-line">Je hoort er nu ook bij!</p>
<button class="button">Okidoki</button>
</div>
</div>
CSS
body,
html {
background-color: #f1f1f1;
height: 100%;
margin: 0;
overflow: hidden;
padding: 0;
width: 100%;
}
body {
background: repeating-radial-gradient(circle, pink, pink 20px, #fff 5px, white 30px);
}
body::after {
background-color: rgba(0, 0, 0, 0.3);
bottom: 0;
content: '';
display: block;
left: 0;
position: absolute;
right: 0;
top: 0;
z-index: 1;
}
#confetti {
height: 100%;
width: 100%;
}
.notification-modal {
background-color: rgba(241, 241, 241, 0.92);
height: 50vh;
position: absolute;
top: 50%;
transform: translateY(-50%);
width: 100%;
z-index: 99999;
}
.notification-content {
margin: 0 auto;
position: absolute;
text-align: center;
transform: translateY(-50%);
top: 50%;
width: 100%;
}
.close-button {
color: #111;
cursor: pointer;
font-size: 25pt;
font-weight: bold;
position: absolute;
right: 10px;
top: 10px;
z-index: 100;
}
.title {
color: #c00;
font-family: monospace;
font-size: 40pt;
font-weight: bold;
}
.tag-line {
color: #0c0;
font-family: monospace;
font-size: 25pt;
font-weight: bold;
}
.button {
background-color: #00c;
border: 0;
border-radius: 50px;
color: #f1f1f1;
cursor: pointer;
font-family: monospace;
font-size: 20pt;
font-weight: bold;
...
JavaScript
(function() {
// const variables
var NUM_CONFETTI = 100,
USE_RANDOM_COLOURS = true,
COLOURS = [[85, 71, 106], [174, 61, 99], [219, 56, 83], [244, 92, 68], [248, 182, 70]],
PI_2 = 2 * Math.PI;
// let variables
var canvas = document.getElementById('confetti'),
context = canvas.getContext('2d'),
confetti = [],
xPosition = 0.5;
/**
* Confetti piece
*
* @constructor
*/
function Confetti() {
this.rgb = USE_RANDOM_COLOURS ? [randomColourComponent(), randomColourComponent(), randomColourComponent()] : COLOURS[~~range(0, COLOURS.length)]
this.r = ~~range(2, 6);
this.r2 = 2 * this.r;
this.xmax = canvas.width - this.r;
this.ymax = canvas.height - this.r;
this.reset();
}
/**
* resets the confetti piece, this idone initially and also when it is out
* of bounds, i.e. opacity < 0 or if it has fallen bellow the max y value.
*/
Confetti.prototype.reset = function() {
this.opacity = 0;
this.dop = 0.03 * range(1, 4);
this.x = range(-this.r2, canvas.width + this.r2);
this.y = range(-this.r2, canvas.height - this.r2);
this.vx = range(0, 2) + 8 * xPosition - 5;
this.vy = 0.7 * this.r + range(-1, 1);
};
/**
* draws this piece on the canvas
*/
Confetti.prototype.draw = function() {
var reference = this.x;
this.x += this.vx;
this.y += this.vy;
this.opacity += this.dop;
if(this.opacity > 1) {
this.opacity = 1;
this.dop *= -1;
}
if(this.opacity < 0 || this.y > this.ymax + this.r2) {
this.reset();
}
if(reference > this.xmax + this.r2 || reference < 0 - this.r2) {
this.x = (reference + this.xmax) % this.xmax;
}
drawCircle(~~this.x, ~~this.y, this.r, `rgba(${this.rgb[0]}, ${this.rgb[1]}, ${this.rgb[2]},...