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.
%button#loadcontrol{:autofocus => true} tap to play
#loading
%p Loading…
%p.msg - Initializing -
#no-audio
%h1 No Web Audio API
%p Sorry, this experiment requires the Web Audio API.
%a{:href => "http://caniuse.com/#feat=audio-api", :target => "_blank"}See browser support
.credits
%span
by
%a{ :href => 'https://pixelia.me', :target => '_blank', :rel => 'noopener noreferrer', :title => 'Noel Delgado' }
%svg{ :height => '12', :viewBox => '0 0 57 30' }
%path{ :d => 'M28.1312,9.5341 C29.7966,9.5341 32.1025,10.627 34.248,12.368 C49.3297,11.5836 53.8793,-0.4796 55.5773,0.6783 C57.8326,3.2476 50.8638,16.3535 39.4,19.088 C39.8655,20.2628 40.1364,21.4786 40.1364,22.6983 C40.1364,25.9478 38.837,26.7409 36.7281,28.8974 L36.704,28.824 C36.4799,29.0276 36.208,29.2318 35.8945,29.4 C35.8945,29.4 36.1346,27.0065 34.9341,26.7672 C34.9341,26.7672 34.3739,27.4054 33.0133,27.2459 C32.8532,25.8896 32.293,25.4109 32.1329,25.3311 C31.4126,25.4109 30.9324,26.5278 30.132,26.5278 C29.8,26.1969 29.5184,25.5615 29.312,24.972 C29.0201,25.4221 28.6036,26.1128 28.2512,26.2885 C27.8796,26.2885 27.1476,25.2858 26.836,24.832 C26.6262,25.4581 26.3285,26.1707 25.9702,26.5278 C25.1699,26.5278 24.6896,25.4109 23.9694,25.3311 C23.8093,25.4109 23.249,25.8896 23.089,27.2459 C21.7284,27.4054 21.1681,26.7672 21.1681,26.7672 C19.9676,27.0065 20.2077,29.4 20.2077,29.4 C19.6122,29.0804 19.1739,28.6307 18.908,28.304 L18.8667,28.3947 C17.1544,26.3262 16.1259,25.5896 16.1259,22.6983 C16.1259,21.4938 16.3637,20.2895 16.784,19.128 C5.2094,16.4922 -1.8448,3.2615 0.4227,0.6783 C2.119,-0.4785 6.6627,11.5578 21.708,12.364 C23.8143,10.6244 26.1724,9.5341 28.1312,9.5341 Z M28.8514,20.3048 C28.8514,20.3048 30.4121,21.7409 32.213,21.7409 C34.0137,21.7409 35.3343,19.3474 35.3343,19.3474 L28.8514,20.3048 Z M20.6879,19.3474 C20.6879,19.3474 22.2486,21.7409 24.0494,21.7409 C25.8502,21.7409 27.1707,20.3048 27.1707,20.3048 L20.6879,19.3474 Z', 'fill-rule' => 'evenodd' }
* {box-sizing: border-box}
body {
font-size: 14px;
margin: 0;
font-family: monospace;
background-color: rgba(0,0,0,1);
color: white;
}
canvas {
display: block;
cursor: pointer;
}
button {
font: inherit;
background: none;
color: inherit;
border: none;
padding: 0;
}
svg {
display: block;
fill: currentColor;
}
#loadcontrol {
cursor: pointer;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
/* loader */
#loading {
opacity: 0;
visibility: hidden;
position: absolute;
top: 50%;
left: 50%;
width: 300px;
transform: translate(-50%, -50%);
transition: all 400ms;
p {
margin: 0;
line-height: 1.5em;
text-align: center;
&.msg {
font-size: .9em;
text-transform: uppercase;
color: #aaa;
}
}
&.show {
opacity: 1;
visibility: visible;
}
}
/* no feature support message */
#no-audio {
display: none;
width: 300px;
position: absolute;
left: 50%;
top: 50%;
padding: 20px 25px;
border: 1px solid #ff667f;
transform: translate(-50%, -50%);
border-radius: 2px;
background: #ff3354;
color: #ffe5ea;
h1 {
font-size: 18px;
margin: 0;
}
a {
text-transform: uppercase;
color: #fff;
}
}
svg {
display: block;
fill: currentColor;
}
.credits {
position: fixed;
bottom: 1rem;
right: 1rem;
font-size: 0.75rem;
& > span {
display: flex;
align-items: center;
justify-content: flex-end;
}
& a {
color: #ff04b0;
}
}
/*
Noel Delgado | @pixelia_me
Music by Ivan Ibarra - Cultos Personales
*/
(function() {
var AudioContext = (window.AudioContext || window.webkitAudioContext);
var PI = Math.PI, TWO_PI = Math.PI * 2, cos = Math.cos, sin = Math.sin, round = Math.round, random = Math.random, floor = Math.floor;
var ctx, actx, analyser, audioBuffer, gainNode, frequencyDataLen, frequencyData, bufferSource;
var startAngle = PI / 180 * -90;
var rotation = 0;
var playing = false, startedAt, pausedAt;
var W, H, CX, CY;
var startElement = document.querySelector('#loadcontrol');
var loadingElement = document.querySelector('#loading');
var loadingMessage = loadingElement.querySelector('.msg');
var settings = {
polygons : 20,
colors : {
background: "rgba(0,0,0,.1)"
},
media : "https://s3-us-west-2.amazonaws.com/s.cdpn.io/9473/ivan-ibarra_-_cultos-personales.mp3",
fftSize : 32, // [32, 64, 128, 256, 512, 1024, 2048]
smoothingTimeConstant : 0.6 // 0.8
};
// feature check.
(function() {
if (!AudioContext) {
return featureNotSupported();
}
startElement.addEventListener('click', initializeAudio);
// initializeAudio();
})();
function featureNotSupported() {
hideStarter();
return document.getElementById('no-audio').style.display = "block";
}
function hideStarter() {
startElement.style.display = 'none';
}
// web audio api supported! let's load the audio
function initializeAudio() {
hideStarter();
loadingElement.classList.add('show');
updateLoadingMessage("- Loading Audio Buffer -");
actx = new AudioContext();
bufferSource = actx.createBufferSource();
var xmlHTTP = new XMLHttpRequest();
xmlHTTP.open('GET', settings.media, true);
xmlHTTP.responseType = 'arraybuffer';
xmlHTTP.onload = function(e) {
updateLoadingMessage("- Decoding Audio File Data -");
actx.decodeAudioData(this.response, function(buffer) {
updateLoadingMessage("- Ready -");
audioBuffer = buffer;
run();
}, function() {alert('Error decoding audio data');});
};
xmlHTTP.send();
}
function updateLoadingMessage(text) {
loadingMessage.textContent = text;
}
function run() {
ctx = document.createElement('canvas').getContext('2d');
analyser = actx.createAnalyser();
analyser.fftSize = settings.fftSize;
analyser.smoothingTimeConstant = settings.smoothingTimeConstant;
// analyser.maxDecibels = -30;
// analyser.minDecibels = -100;
gainNode = actx.createGain();
gainNode.connect(analyser);
analyser.connect(actx.destination);
frequencyDataLen = analyser.frequencyBinCount;
frequencyData = new Uint8Array(frequencyDataLen);
document.body.appendChild(ctx.canvas);
document.getElementById('loading').className = "hide";
play();
resizeHandler();
ctx.canvas.addEventListener('click', toggleAudio);
window.addEventListener('resize', resizeHandler);
}
function animate() {
if (!playing) return;
requestAnimationFrame(animate);
update();
}
function update() {
var i, sides, radius, r, g, b, a, avg = 0;
ctx.beginPath();
ctx.globalCompositeOperation = "source-over";
ctx.fillStyle = settings.colors.background;
ctx.fillRect(0,0,W,H);
ctx.closePath();
analyser.getByteFrequencyData(frequencyData);
for (i = 0; i < frequencyDataLen; i++) {
avg += frequencyData[i];
}
avg = (avg / frequencyDataLen);
sides = floor(avg / 24);
for (i = 0; i < settings.polygons; i++) {
radius = (avg * i / 10) + 10;
r = 255;
g = 0;
b = round(random() * radius);
a = (255 / radius);
if (avg < 80) {
rotation = 0;
g = b = 255;
a = 0.25;
}
if (avg > 140) {
rotation += 1;
r = 124;
g = 220;
b = 255;
a = 1;
}
ctx.beginPath();
ctx.globalCompositeOperation = "lighter";
createPolygon(ctx, CX, CY, radius, sides, startAngle, 0);
ctx.lineWidth = 1;
ctx.strokeStyle = 'rgba('+r+','+g+','+b+','+a+')';
ctx.stroke();
ctx.closePath();
}
}
function createPolygon(ctx, x, y, radius, sides, startAngle) {
if (sides < 3) sides = 3;
var a = (TWO_PI) / sides;
ctx.save();
ctx.translate(x, y);
ctx.rotate(startAngle + rotation);
ctx.moveTo(radius, 0);
for (var i = 1; i < sides; i++) {
ctx.lineTo(radius * cos(a * i), radius * sin(a * i));
}
ctx.closePath();
ctx.restore();
}
function toggleAudio() {
if (playing) pause(); else play();
}
function play() {
playing = true;
startedAt = pausedAt ? Date.now() - pausedAt : Date.now();
bufferSource = null;
bufferSource = actx.createBufferSource();
bufferSource.buffer = audioBuffer;
bufferSource.loop = true;
bufferSource.connect(gainNode);
if (pausedAt) bufferSource.start(0, pausedAt / 1000);
else bufferSource.start();
animate();
}
function pause() {
playing = false;
pausedAt = Date.now() - startedAt;
bufferSource.stop();
}
function resizeHandler() {
W = ctx.canvas.width = window.innerWidth;
H = ctx.canvas.height = window.innerHeight;
CX = W / 2;
CY = H /2;
}
})();
Also see: Tab Triggers