<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Key Sequence Detection</title>
<link rel="stylesheet" href="./styles.css"/>
</head>
<body>
<h1 class="title">Key Sequence<br>Detection</h1>
<p class="instruction">Enter the word 'donut'</p>
<iframe id="gif" src="https://giphy.com/embed/l41lZxzroU33typuU" width="480" height="321"></iframe>
<p><a href="https://giphy.com/gifs/full-house-michelle-tanner-you-got-it-dude-l41lZxzroU33typuU"></a></p>
<script src="./scripts.js"></script>
</body>
</html>
@import url('https://fonts.googleapis.com/css?family=BioRhyme+Expanded:800|Raleway');
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
height: 100vh;
display: flex;
justify-content: space-evenly;
align-items: center;
flex-direction: column;
background: linear-gradient(to right, #396afc, #2948ff);
}
.title {
color: #FFCC29;
font-family: 'BioRhyme Expanded', serif;
font-size: 40px;
text-align: center;
text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.2);
}
.instruction {
font-family: 'Raleway', sans-serif;
font-size: 20px;
}
#gif {
display: none;
border: none;
}
#gif.show {
display: block;
animation: bounceDownIn 0.35s ease-in-out both;
}
@keyframes bounceDownIn {
0% { opacity: 0; transform: translateY(-2000px); }
60% { opacity: 1; transform: translateY(30px); }
80% { transform: translateY(-10px); }
100% { transform: translateY(0); }
}
@media screen and (max-width: 500px) {
.title { font-size: 30px; }
#gif { height: 50vh; }
}
const gif = document.querySelector('iframe'),
sequenceToMatch = 'donut';
let inputSequence = [];
function detectKeySequence(e) {
inputSequence.push(e.key);
inputSequence.splice(-sequenceToMatch.length - 1, inputSequence.length - sequenceToMatch.length);
let isMatch = inputSequence.join('') === sequenceToMatch;
isMatch && gif.classList.add('show');
}
window.addEventListener('keyup', detectKeySequence);