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 URLs 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 its URL and the proper URL extension.
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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<!-- Make something fun and interactive -->
<!-- Press left or right on your keyboard! -->
<div id="vuenicorn-contest">
<h1>Simon - A game of memory skill</h1>
<p class="gameover" :class="{ hidden: !gameover }">GAMEOVER!</p>
<button class="start-game" :class="{ hidden: !notPlaying }" @click="startGame">
{{ gameover ? 'Retry' : 'Start Game'}}
</button>
<svg :width="windowWidth"
:height="windowHeight"
>
<title>VueConf Toronto Logo</title>
<g :transform="`translate(${logoPosition.x}, ${logoPosition.y})`">
<g>
<polygon @click="choose('darkBlue')" :fill="usedColors.darkBlue"
points="0.71875 98.9003906 36.0913086 99.5170898 18.375 69.0234375"></polygon>
<polygon @click="choose('darkBlue')" :fill="usedColors.darkBlue"
transform="translate(143.180054, 84.063232) scale(1, -1) translate(-143.180054, -84.063232)"
points="125.901855 99.0178223 160.458252 99.5625 143.65625 68.5639648"></polygon>
<polygon @click="choose('purple')" :fill="usedColors.purple"
points="18 69.21875 35.8310547 99.3452148 53.6621094 69"></polygon>
<polygon @click="choose('purple')" :fill="usedColors.purple"
transform="translate(161.589844, 84.067383) scale(1, -1) translate(-161.589844, -84.067383)"
points="143.517578 68.5175781 160.479492 99.6171875 179.662109 68.5175781"></polygon>
<polygon @click="choose('pomegranate')" :fill="usedColors.pomegranate"
points="0.931640625 99.015625 35.9980469 99.2988281 73.4584961 161.203125 55.1181641 192.684082"></polygon>
<polygon @click="choose('pomegranate')" :fill="usedColors.pomegranate"
transform="translate(116.946777, 115.671143) scale(-1, 1) translate(-116.946777, -115.671143)"
points="89.9208984 98.7011719 107.97168 69 143.972656 131.498047 126.155762 162.342285"></polygon>
<polygon @click="choose('skyBlue')" :fill="usedColors.skyBlue"
points="35.7519531 98.9140625 53.6708984 68.8798828 89.9140625 131.990234 73.2851562 161.142578"></polygon>
<polygon @click="choose('sunshine')" :fill="usedColors.sunshine"
points="107.69873 162.451172 125.780273 192.767578 179.498047 99.5761719 143.942383 98.703125"></polygon>
<polygon @click="choose('darkBlue')" :fill="usedColors.darkBlue"
points="72.1601562 223.043945 54.9453125 192.087891 73.390625 160.777344 89.375 192.066406"></polygon>
<polygon @click="choose('skyBlue')" :fill="usedColors.skyBlue"
points="72.1193848 223.072388 107.859375 224.300781 125.692383 192.624023 89.0292969 192.624023"></polygon>
<polygon @click="choose('purple')" :fill="usedColors.purple"
points="72.8603516 162.036133 89.8085938 131.283203 125.591797 192.580078 88.7998047 192.580078"></polygon>
<polygon @click="choose('darkBlue')" :fill="usedColors.darkBlue"
points="65.9648438 44.6640625 113.873047 45.0136719 90.1796875 0.451171875"></polygon>
<polygon @click="choose('skyBlue')" :fill="usedColors.skyBlue"
transform="translate(89.954102, 66.281250) scale(1, -1) translate(-89.954102, -66.281250)"
points="66 88.2128906 113.908203 88.5625 90.2148438 44"></polygon>
</g>
</g>
</svg>
</div>
// This certers the logo in the middle of the page
// Feel free to remove and customize to your liking
body {
padding: 64px 0;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
#vuenicorn-contest {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
.start-game {
border: none;
padding: 22px 32px;
font-size: 24px;
font-weight: bold;
text-transform: uppercase;
letter-spacing: 1px;
border-radius: 8px;
background-color: hotpink;
color: #fff;
margin-bottom: 32px;
}
.hidden {
opacity: 0;
pointer-events: none;
}
.gameover {
font-size: 32px;
}
svg > g {
margin: 0 auto;
}
h1 {
padding: 0;
margin: 0;
}
new Vue({
el: '#vuenicorn-contest',
data() {
const windowWidth = window.innerWidth
const windowHeight = window.innerHeight
const logoWidth = 180
const logoHeight = 225
return {
gameover: false,
progress: 0,
notPlaying: true,
logoPosition: {
x: (windowWidth - logoWidth) / 2,
y: 64
},
colors: {
purple: '#5D2B7B',
purpleHighlight: '#7D4B5B',
darkBlue: '#3A3A96',
darkBlueHighlight: '#5A5AB6',
pomegranate: '#ED3624',
pomegranateHighlight: '#FD5644',
sunshine: '#FEE104',
sunshineHighlight: '#FEF124',
skyBlue: '#30B9ED',
skyBlueHighlight: '#50D9FD'
},
usedColors: {
purple: '#5D2B7B',
darkBlue: '#3A3A96',
pomegranate: '#ED3624',
sunshine: '#FEE104',
skyBlue: '#30B9ED'
},
windowWidth,
windowHeight,
options: ['purple', 'darkBlue', 'pomegranate', 'sunshine', 'skyBlue'],
pattern: []
}
},
methods: {
getRandomColor() {
const random = Math.floor(Math.random() * this.options.length);
return this.options[random];
},
highlightPattern() {
this._highlight(0);
},
_highlight(index) {
setTimeout(() => {
this.usedColors[this.pattern[index]] = this.colors[`${this.pattern[index]}Highlight`];
setTimeout(() => {
this.usedColors[this.pattern[index]] = this.colors[`${this.pattern[index]}`];
if (!this.pattern[index + 1]) { return; }
this._highlight(index + 1);
}, 500);
}, 200);
},
gameLoop() {
this.gameover = false;
this.progress = 0;
const randomColor = this.getRandomColor();
this.pattern.push(randomColor);
this.highlightPattern();
},
startGame() {
this.notPlaying = false;
setTimeout(() => {
this.gameLoop();
}, 500);
},
choose(color) {
if (this.pattern[this.progress] === color) {
this.progress++;
this.usedColors[color] = this.colors[`${color}Highlight`];
setTimeout(() => {
this.usedColors[color] = this.colors[`${color}`];
}, 300);
} else {
this.endGame();
return;
}
if (this.progress >= this.pattern.length) {
setTimeout(() => {
this.gameLoop();
}, 1000);
}
},
endGame() {
this.notPlaying = true;
this.gameover = true;
this.pattern = [];
this.progress = 0;
}
}
})
Also see: Tab Triggers