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.
<a-scene>
<a-assets timeout="10000">
<a-mixin id="circle" geometry="primitive: circle; radius: 0.3;" material="color: black;" rotation="-90 0 0"></a-mixin>
<template id="chris" type="text/html">
<a-sphere color="#ffe0bd">
<a-entity id="#eyes" position="0 0.3 1">
<a-circle color="#333" radius="0.1" position="0.3 0 0"></a-circle>
<a-circle color="#333" radius="0.1" position="-0.3 0 0"></a-circle>
<a-animation attribute="rotation"
delay="3200"
dur="250"
fill="forwards"
to="360 0 0"
repeat="indefinite"></a-animation>
</a-entity>
<a-box color="#ffad60" height="0.5" width="0.2" depth="0.2" position="0 0.2 0.9" rotation="-25 0 0" ></a-box>
<a-sphere color="#6a4e42" radius="1.01" phi-start="0" phi-length="50" rotation="-30 0 90" opacity="0.2"></a-sphere>
<a-torus color="#333" arc="135" radius="0.25" rotation="2d0 0 200" position="0 -0.25 1" radius-tubular="0.01"></a-torus>
</a-sphere>
</template>
<template id="dave" type="text/html">
<a-sphere color="#ffe0bd">
<a-entity id="#eyes" position="0 0.3 1">
<a-circle color="#333" radius="0.1" position="0.3 0 0"></a-circle>
<a-circle color="#333" radius="0.1" position="-0.3 0 0"></a-circle>
<a-animation attribute="rotation"
delay="3000"
dur="250"
fill="forwards"
to="360 0 0"
repeat="indefinite"></a-animation>
</a-entity>
<a-box color="#ffad60" height="0.5" width="0.2" depth="0.2" position="0 0.2 0.9" rotation="-25 0 0" ></a-box>
<a-sphere color="#6a4e42" radius="1.05" position="0 0.2 -0.05" phi-start="0" phi-length="180" rotation="-115 22 0" side="double"></a-sphere>
<a-sphere color="#6a4e42" radius="1.05" position="0 0.2 -0.07" phi-start="0" phi-length="180" rotation="-130 -20 0" side="double"></a-sphere>
<a-torus color="#6a4e42" arc="180" radius="1" radius-tubular="0.05" rotation="30 180 180" position="0 0.2 0.2" ></a-torus>
<a-torus color="#6a4e42" arc="180" radius="0.5" radius-tubular="0.05" rotation="-45 180 0" position="0 -0.55 0.6"></a-torus>
</a-sphere>
</a-entity>
</template>
<template id="hole" type="text/html">
<a-circle mixin="circle">
<a-sphere radius="0.2" position="0 0 -1" color="transparent" rotation="62.5 0 0">
<a-entity template="src: #${mole}" scale="0.21 0.21 0.21"></a-entity>
<a-animation begin="down" dur="1000" easing="ease-out" attribute="position" fill="forwards" from="0 0 0.25" to="0 0 -0.5"></a-animation>
<a-animation begin="up" easing="ease-out" attribute="position" fill="forwards" from="0 0 -1" to="0 0 0.25"></a-animation>
<a-animation begin="shake" attribute="rotation" dur="500" fill="backwards" to="360 360 0"></a-animation>
</a-sphere>
</a-circle>
</template>
<img id="wood" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/17/reclaimed_wood.jpg" crossorigin="anonymous">
</a-assets>
<!-- Environment -->
<a-box color="#F96C06" position="0 0.25 -3" width="3" depth="2" rotation="15 0 0">
<a-entity id="decorative-holes">
<a-entity template="src: #hole" data-mole="dave" position="0 0.51 -0.5"></a-entity>
<a-entity template="src: #hole" data-mole="chris" position="0 0.51 0.5"></a-entity>
<a-entity template="src: #hole" data-mole="chris" position="1 0.51 -0.5"></a-entity>
<a-entity template="src: #hole" data-mole="dave" position="1 0.51 0.5"></a-entity>
<a-entity template="src: #hole" data-mole="chris" position="-1 0.51 -0.5"></a-entity>
<a-entity template="src: #hole" data-mole="dave" position="-1 0.51 0.5"></a-entity>
</a-entity>
<a-sphere id="startBtn" color="green" radius="0.1" position="1.3 0.3 0.95">
<a-animation begin="click" dur="100" attribute="position" fill="backwards" to="1.3 0.3 0.93"></a-animation>
</a-sphere>
</a-box>
<!-- UI -->
<a-text value="TIME" position="-1.2 2.2 -4" font='mozillavr' wrap-count="30"></a-text>
<a-text id="timer" value="60" position="-1.3 2 -4" font='mozillavr' wrap-count="10"></a-text>
<a-text value="SCORE" position="0.3 2.2 -4" font='mozillavr' wrap-count="30"></a-text>
<a-text id="score" value="0" position="0.3 2 -4" font='mozillavr' wrap-count="10"></a-text>
<!-- Environment -->
<a-sky color="#000000"></a-sky>
<a-plane color="#6a4e42" material="src: #wood; repeat: 10 10" height="20" width="20" rotation="-90 0 90" shader="flat"></a-plane>
<!-- <a-entity id="muzak" sound="src: https://s3-us-west-2.amazonaws.com/s.cdpn.io/17/carnival.mp3; volume: 0.4; poolSize: 4;"></a-entity>
-->
<!-- Camera -->
<a-camera universal-controls>
<a-cursor fuse-timeout="200" color="#0099FF"></a-cursor>
</a-camera>
</a-scene>
<audio id="audio2" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/17/carnival.mp3"></audio>
var moles = document.querySelectorAll('a-circle > a-sphere');
var score = 0;
var scoreEl = document.querySelector('#score');
var timerEl = document.querySelector('#timer');
// var musicEl = document.querySelector('#muzak');
var musicEl2 = document.querySelector('#audio2');
var startBth = document.querySelector('#startBth');
var gameover = true;
var gameTimer;
// Let's automate them moles!
var automateMoles = function(){
for(let i=0;i<moles.length;i++) {
let mole = moles[i];
// Make the mole pop up.
let up = function(){
if(!mole.is('up') && !gameover) {
mole.emit('jump');
mole.addState('up');
if(!gameover) {
moleTimer = window.setTimeout(down, Math.max(1000, Math.random() * 3000));
} else {
down();
}
}
};
// Make the mole go down, either on timeout or click.
let down = function() {
mole.emit('down');
mole.removeState('up');
if(!gameover) {
moleTimer = window.setTimeout(up, Math.max(2000, Math.random() * 15000));
}
};
// When clicked or focus-clicked...
// Update the scoreboard.
mole.addEventListener('click', function(){
if(mole.is('up')) {
mole.emit('shake');
score++;
scoreEl.setAttribute('value', score);
down();
}
});
let moleTimer = window.setTimeout(up, Math.random() * 12000);
}
}
// Update the timer every 1s.
var updateTimer = function(){
let currTime = parseInt(timerEl.getAttribute('value'), 10);
if(currTime === 0) {
// Finish State
gameover = true;
// musicEl.components.sound.stopSound();
musicEl2.pause();
musicEl2.currentTime = 0;
} else {
// Update Timer
timerEl.setAttribute('value', currTime - 1);
gameTimer = window.setTimeout(updateTimer, 1000);
}
};
// Start the game
// Reset the scoreboard and timer
// Unfreeze the gameover state
// Start the timer
var startGame = function() {
score = 0;
scoreEl.setAttribute('value', 0);
timerEl.setAttribute('value', 60);
gameover = false;
// musicEl.components.sound.playSound();
musicEl2.play();
window.clearTimeout(gameTimer);
window.setTimeout(automateMoles, 100);
gameTimer = window.setTimeout(updateTimer, 100);
}
// When the start button is clicked...
// start the the game.
startBtn.addEventListener('click', startGame);
Also see: Tab Triggers