Add transition to menu opening

This commit is contained in:
Marcel
2017-12-17 19:50:46 +01:00
parent e42d65f4b6
commit 41f702a18b
5 changed files with 64 additions and 24 deletions

View File

@@ -33,7 +33,7 @@ const de = {
reset: "Zurücksetzen" reset: "Zurücksetzen"
}; };
let currentLang = "en"; let currentLang = ["de", "en"].includes(navigator.language || navigator.userLanguage) ? navigator.language || navigator.userLanguage : "en";
let firstRun = true; let firstRun = true;
class Language { class Language {

49
menu.js
View File

@@ -55,22 +55,55 @@ function toggleMenu() {
} }
} }
function fadeBlurIn() {
const blurEl = document.getElementById("f1").children[0];
const finalVal = 15;
let currentVal = 0;
const id = setInterval(frame, 1);
function frame() {
if(currentVal >= finalVal) {
clearInterval(id);
} else {
currentVal += 0.1;
blurEl.setAttribute("stdDeviation", currentVal);
}
}
}
function fadeBlurOut() {
const blurEl = document.getElementById("f1").children[0];
const finalVal = 0;
let currentVal = 15;
const id = setInterval(frame, 1);
function frame() {
if(currentVal <= finalVal) {
clearInterval(id);
} else {
currentVal -= 0.1;
blurEl.setAttribute("stdDeviation", currentVal);
}
}
}
function showMenu() { function showMenu() {
isPaused = true; isPaused = true;
document.getElementById("background").classList.add("blurred"); document.getElementById("game-title").style.opacity = "1";
document.getElementById("game-title").style.display = "block"; document.getElementById("game-play").style.opacity = "1";
document.getElementById("game-play").style.display = "block"; fadeBlurIn();
if(!firstRun) { if(!firstRun) {
document.getElementById("game-reset").style.display = "block"; document.getElementById("game-reset").style.opacity = "1";
} }
} }
function hideMenu() { function hideMenu() {
isPaused = false; isPaused = false;
document.getElementById("background").classList.remove("blurred"); // document.getElementById("background").classList.remove("blurred");
document.getElementById("game-title").style.display = "none"; document.getElementById("game-title").style.opacity = "0";
document.getElementById("game-play").style.display = "none"; document.getElementById("game-play").style.opacity = "0";
document.getElementById("game-reset").style.display = "none"; document.getElementById("game-reset").style.opacity = "0";
fadeBlurOut();
if(!firstRun) { if(!firstRun) {
update(lastTime); update(lastTime);
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "Tetris.js", "name": "Tetris.js",
"version": "0.0.1", "version": "0.0.2",
"main": "main.js", "main": "main.js",
"description": "Tetris.js is a decent but cool clone of the retro game classic Tetris", "description": "Tetris.js is a decent but cool clone of the retro game classic Tetris",
"scripts": { "scripts": {

View File

@@ -14,6 +14,7 @@ body {
top: 10px; top: 10px;
font-size: 14px; font-size: 14px;
font-weight: 300; font-weight: 300;
z-index: 1;
} }
.lang { .lang {
@@ -31,8 +32,10 @@ body {
#game-title { #game-title {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 25%; top: 50%;
transform: translate(-50%, -25%); transform: translate(-50%, -25%) translateY(-200px);
opacity: 1;
transition: opacity .5s;
} }
#game-play, #game-reset { #game-play, #game-reset {
@@ -44,30 +47,34 @@ body {
height: 75px; height: 75px;
font-size: 30px; font-size: 30px;
box-shadow: none; box-shadow: none;
color: #ffff; color: #ffff !important;
background: #3877FF; background: #3877FF !important;
border: 0; border: 0 !important;
border-radius: 0; border-radius: 0 !important;
transition: box-shadow .2s; transition: box-shadow .2s, opacity .5s;
cursor: pointer; cursor: pointer;
opacity: 1;
} }
#game-reset { #game-reset {
display: none; display: none;
background-color: #FF0D72; background-color: #FF0D72 !important;
transform: translate(-50%, -50%) translateY(85px); transform: translate(-50%, -50%) translateY(85px);
opacity: 0;
} }
#game-play:hover, #game-play:active, #game-play:focus { #game-play:hover, #game-play:active, #game-play:focus {
outline: none; outline: none !important;
box-shadow: 3px 4px 0 3px rgba(0,0,0,0.2); box-shadow: 3px 4px 0 3px rgba(0,0,0,0.2) !important;
} }
#background { #background {
width: 100%; width: 100%;
height: 100%; height: 100%;
position: absolute; position: absolute;
left: 0; left: 0;
top: 0; top: 0;
filter: none;
} }
#background.blurred { #background.blurred {

View File

@@ -76,10 +76,10 @@ function createPiece(type) {
]; ];
case 'I': case 'I':
return [ return [
[0, 5, 0, 0], [0, 0, 5, 0],
[0, 5, 0, 0], [0, 0, 5, 0],
[0, 5, 0, 0], [0, 0, 5, 0],
[0, 5, 0, 0] [0, 0, 5, 0]
]; ];
case 'S': case 'S':
return [ return [