HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
section.game
.game__inner.container
.screen
h1.screen__headline Aim Training
h3.screen__subheading
span.warn Attention!  
| If you don't hit the ball, you will lose
button.screen__start Start
.screen
h1.screen__headline Choise time
ul.time__list
li.time__item
button.time__btn(data-time='10') 10 Sec
li.time__item
button.time__btn(data-time='20') 20 Sec
li.time__item
button.time__btn(data-time='30') 30 Sec
li.time__item.field
input.time__field(type='number' placeholder='Another... (In seconds)')
button.time__field-btn(type='submit')
.screen
h3.screen__title Time left  
span.screen__timer 00:00
.screen__board
.game-over.hide
button.game-over__restart Restart
@import url('https://fonts.googleapis.com/css2?family=Comfortaa:wght@400;500;700&display=swap');
$black: #000;
$white: #fff;
$almostWhite: #CFD8DC;
$primary: #F57C00;
$primaryLight: #ffa726;
$secondary: #9142e0;
$secondaryLight: #c49aef;
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
height: 100vh;
margin: 0;
overflow: hidden;
color: $white;
font-family: 'Comfortaa', sans-serif;
text-align: center;
background: #1b1c22;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
button {
color: inherit;
border: none;
cursor: pointer;
}
.container {
position: relative;
width: 100vw;
height: 100vh;
overflow: hidden;
}
.screen {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 100vw;
height: 100vh;
transition: margin 0.5s ease-out;
&.up {
margin-top: -100vh;
}
&__headline {
margin-bottom: 20px;
font-size: 64px;
}
&__subheading {
margin-bottom: 50px;
color: $primaryLight;
}
&__start {
padding: 10px 30px;
font-size: 24px;
background: none;
border-radius: 5px;
transition: 0.5s;
}
&__board {
position: relative;
display: flex;
align-items: center;
justify-content: center;
width: 500px;
height: 500px;
overflow: hidden;
background: none;
border-radius: 30px;
transition: .5s;
}
&__title {
font-size: 24px;
margin-bottom: 30px;
}
&__timer {
color: $secondary;
}
}
.time {
&__list {
display: flex;
flex-wrap: wrap;
justify-content: center;
gap: 20px;
padding: 0;
list-style: none;
}
&__item {
display: flex;
color: $white;
border: 2px solid $almostWhite;
border-radius: 5px;
transition: .2s;
&:not(:last-child):hover {
color: $secondary;
border: 2px solid $secondary;
}
}
&__btn {
padding: 0.5rem 1rem;
font-family: inherit;
font-size: 1.5rem;
background-color: transparent;
border-radius: 5px;
cursor: pointer;
&:hover {
color: $secondary;
transition: .1s;
}
}
&__field {
display: flex;
padding: 0.5rem 1rem;
color: $white;
font-family: inherit;
font-size: 1.5rem;
background-color: transparent;
border: none;
border-radius: 5px 0 0 5px;
cursor: pointer;
&:focus {
outline: none;
}
&::placeholder {
font-size: 22px;
}
&-btn {
position: relative;
width: 30px;
background: $almostWhite;
border-radius: 0 2px 2px 0;
transition: .2s;
&:before {
position: absolute;
top: 50%;
left: 30%;
width: 10px;
height: 2px;
background: #fff;
border-radius: 2px;
content: '';
}
&::after {
position: absolute;
top: 50%;
left: 30%;
width: 10px;
height: 2px;
transform: rotate(90deg);
background: #fff;
border-radius: 2px;
content: '';
}
&:hover {
background: $secondary;
&:before, &:after {
background: $white;
}
}
}
}
}
.hide {
opacity: 0;
visibility: hidden;
pointer-events: none;
}
.primary {
color: $secondary;
}
.circle {
position: absolute;
background: $secondaryLight;
border-radius: 50%;
transition: .5s;
cursor: pointer;
}
.warn {
color: $primary;
}
.game-over {
position: absolute;
display: flex;
flex-direction: column;
&__message {
display: flex;
flex-direction: column;
margin-bottom: 50px;
color: $primaryLight;
font-size: 24px;
& > span {
margin-bottom: 5px;
color: $primary;
font-size: 28px;
}
& p {
&:not(:last-child) {
margin-bottom: 15px;
}
& > span {
color: $secondary;
}
}
}
&__restart {
margin-top: 300px;
padding: 10px 30px;
font-size: 24px;
background: none;
border-radius: 5px;
transition: 0.5s;
}
}
const screen = document.querySelectorAll('.screen');
const btnStart = document.querySelector('.screen__start');
const restart = document.querySelector('.game-over');
const btnReStart = document.querySelector('.game-over__restart');
const timeList = document.querySelector('.time__list');
const field = document.querySelector('.field');
const timer = document.querySelector('.screen__timer');
const hasFocus = document.querySelector('.time__field');
const btnTime = document.querySelector('.time__field-btn');
const board = document.querySelector('.screen__board');
const circle = document.querySelector('.circle');
// Counter(-Stricke :3)
let time = 0;
let score = 0;
let inputValue;
let isOver = false;
let inter;
let interInput;
// Func / Start
// Set time
const setTime = (value) => {
timer.innerHTML = value;
}
// Get random number
const getRndNum = (min, max) => {
return Math.round(Math.random() * (max - min) + min);
}
// Get random HEX color
const getRndColor = () => {
const rndColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
return rndColor;
};
// Get value from input
const getInputValue = () => {
const value = document.querySelector('.time__field').value;
if (value !== 0 && value.length > 0) {
inputValue = value;
screen[1].classList.add('up');
}
}
// Decrease time (Buttons)
const decTime = () => {
if (time === 0) {
gameEnd();
} else if (isOver === true) {
board.innerHTML = ''
restart.classList.remove('hide');
gameOver();
} else {
let current = --time
if (current < 10) {
current = `0${current}`
}
setTime(`00:${current}`)
}
};
// Decrease time (Input)
const decTimeInput = () => {
if (inputValue === 0) {
gameEnd();
} else if (isOver === true) {
board.innerHTML = ''
restart.classList.remove('hide');
gameOver();
} else {
let value = --inputValue;
const seconds = value % 60;
const secondsInMinutes = (value - seconds) / 60;
const minutes = secondsInMinutes % 60;
const hours = (secondsInMinutes - minutes) / 60;
let current = `${hours}:${minutes}:${seconds}`;
if (hours < 10 && hours !== 0) {
current = `0${hours}:${minutes}:${seconds}`;
} else if (hours === 0 && minutes > 10) {
current = `${minutes}:${seconds}`;
} else if (minutes < 10 && seconds > 10) {
current = `0${minutes}:${seconds}`;
} else if (seconds < 10) {
current = `0${minutes}:0${seconds}`;
}
setTime(current);
}
}
// Create circle on a board
const createRndCircle = () => {
const circle = document.createElement('div');
circle.classList.add('circle');
// Sets dynamic random size and background color
setInterval(() => {
const { width, height } = board.getBoundingClientRect();
const s = getRndNum(10, 60);
const x = getRndNum(0, width - s);
const y = getRndNum(0, height - s);
circle.style.width = `${s}px`;
circle.style.height = `${s}px`;
circle.style.top = `${x}px`;
circle.style.left = `${y}px`;
circle.style.background = getRndColor();
}, 1000);
board.append(circle);
}
// Sets the params when starting the game. (Buttons)
const gameStart = () => {
timer.innerHTML = '00:00';
timer.parentElement.classList.remove('hide');
board.innerHTML = '';
isOver = false;
inter = setInterval(decTime, 1000);
createRndCircle();
}
// Sets the params when starting the game. (Input)
const gameStartInput = () => {
timer.innerHTML = '00:00';
timer.parentElement.classList.remove('hide');
board.innerHTML = '';
isOver = false;
interInput = setInterval(decTimeInput, 1000);
createRndCircle();
}
// Sets the params when ending the game.
const gameEnd = () => {
timer.parentElement.classList.add('hide');
board.innerHTML = `<h1>Cчёт <span class='primary'>${score}</span></h1>`;
}
// Sets the params if the game over
const gameOver = () => {
timer.parentElement.classList.add('hide');
board.innerHTML = `<h3 class='game-over__message'>
<span>Fail (ノಠ益ಠ)ノ彡┻━┻</span>
<p>You lose :(<p>
<p>Your count: <span>${score}</span></p>
</h3>`
clearInterval(inter);
clearInterval(interInput);
}
// Sets dynamic color and box shadow
setInterval(() => {
btnStart.style.color = getRndColor();
btnStart.style.boxShadow = `0px 0px 30px -5px ${getRndColor()}`;
btnReStart.style.color = getRndColor();
btnReStart.style.boxShadow = `0px 0px 30px -5px ${getRndColor()}`;
board.style.boxShadow = `0px 0px 20px -5px ${getRndColor()}`;
}, 100);
// Func / End
// Listeners / Start
btnTime.addEventListener('click', () => {
getInputValue();
gameStartInput();
});
btnStart.addEventListener('click', () => screen[0].classList.add('up'));
btnReStart.addEventListener('click', () => {
screen[1].classList.remove('up');
restart.classList.add('hide');
});
board.addEventListener('click', (e) => {
if (e.target.classList.contains('circle')) {
score++;
e.target.remove();
createRndCircle();
} else {
isOver = true;
}
})
timeList.addEventListener('click', (e) => {
if (e.target.classList.contains('time__btn')) {
time = parseInt(e.target.getAttribute('data-time'));
screen[1].classList.add('up');
gameStart();
}
});
hasFocus.addEventListener('focusin', () => {
field.style.border = '2px solid #9142e0';
btnTime.style.background = '#9142e0';
})
hasFocus.addEventListener('focusout', () => {
field.style.border = '2px solid #CFD8DC';
btnTime.style.background = '#CFD8DC';
})
// Listeners / End
Also see: Tab Triggers