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.
<div id="bubble-container" class="animakuz-container gradient-bg-blue">
<!-- bubble prototype -->
<!-- <div class="bubble bubble-part bubble-1">
<div class="soft-light base-light bubble-part">
</div>
<div class="mid-light top-light bubble-part">
</div>
<div class="mid-light bottom-light bubble-part">
</div>
<div class="hard-light off-light-1 bubble-part">
</div>
<div class="hard-light off-light-2 bubble-part">
</div>
</div> -->
<!-- options -->
<button id="btn-show-options">^</button>
<div id="options" class="box">
<p class="options-title">
<span class="title-text">Bubble Options</span>
<button id="btn-hide-options">X</button>
</p>
<p class="options-body">
<label>Bubble Density</label>
<input id="txt-bubble-density" type="text" value="10">
<button id="btn-generate">Generate</button>
</p>
</div>
<!-- show error message on input to bubble density -->
<div id="message-box" class="box message-box error-message">
<p id="message-line" class="message">
<span id="message-icon" class="error-icon">!</span>
<span id="message-text">Error</span>
</p>
<button id="message-button">OK</button>
</div>
</div>
/* interface */
body, html {
overflow: hidden;
}
/* boxes */
.box {
border-radius: 5px;
border: 1px solid rgba(200,200,250,0.4);
background-color: rgba(150,150,200,0.4);
box-shadow: 0 2px 4px rgba(50,50,100,0.4);
}
.active-box {
display: block !important;
}
#btn-show-options, #options {
position: absolute;
left: 50%;
transform: translateX(-50%);
z-index: 2;
}
#btn-show-options {
display: block;
bottom: 10px;
height: 32px;
padding: 4px 14px 0;
font-size: 32px;
border-radius: 4px;
cursor: pointer;
border: 1px solid rgba(200,200,250,0.2);
box-shadow: 0 2px 4px rgba(50,50,100,0.2);
background-color: rgba(60,60,200,0.2);
color: rgba(220,220,240,0.8);
}
#btn-show-options:hover {
background-color: rgba(60,60,200,0.8);
color: rgba(220,220,240,1);
}
#options {
display: none;
bottom: 10%;
}
.options-title {
margin: 0;
height: 24px;
line-height: 24px;
background-color: rgba(50,50,150,0.2);
border-radius: 5px 5px 0 0;
}
.options-title .title-text {
margin-left: 10px;
color: #dedede;
}
#btn-hide-options {
cursor: pointer;
position: absolute;
right: 0;
top: 0;
border-radius: 5px;
border: 0;
height: 24px;
width: 24px;
font-size: 12px;
font-weight: bold;
background-color: rgba(200,60,60,0.8);
color: rgb(240,220,220);
}
#btn-hide-options:hover {
color: rgba(200,60,60,0.8);
background-color: rgb(240,220,220);
}
.options-body {
margin: 20px 20px 10px;
}
.options-body label {
color: #dedede;
margin-right: 10px;
}
#txt-bubble-density {
width: 40px;
text-align: center;
border: 1px solid rgba(0,0,0,0.14);
border-radius: 4px;
padding: 2px 5px;
}
#btn-generate {
border: 0;
cursor: pointer;
border-radius: 5px;
padding: 8px 10px;
margin-left: 4px;
background-color: rgba(20,150,20, 0.8);
color: rgb(220,240,220);
}
#btn-generate:hover {
background-color: rgb(220,240,220);
color: rgba(10,100,10, 0.8);
}
@media (max-width: 767px) {
#options {
}
.options-body label {
display: block;
margin: 5px auto 10px;
text-align: center;
}
}
#txt-bubble-density {
}
#btn-generate {
}
.message-box {
display: none;
padding: 14px 20px 10px;
position: absolute;
top: 30%;
left: 50%;
transform: translateX(-50%);
text-align: center;
}
.message-box .message {
margin: 0 auto 15px;
/* font-weight: bold;*/
text-align: center;
}
.message-box #message-icon {
display: inline-block;
margin-right: 5px;
width: 20px;
height: 20px;
line-height: 22px;
text-align: center;
border-radius: 50%;
color: #fff;
}
.message-box #message-button {
border: 0;
border-radius: 5px;
padding: 4px 16px;
cursor: pointer;
color: #fff;
background-color: rgba(50,100,150, 0.8);
}
.message-box #message-button:hover {
color: rgba(50,100,150, 0.8);
background-color: rgba(250,250,250,0.8);
}
.error-message {
color: rgb(200,20,20);
}
.error-icon {
background-color: rgba(255,50,50,1);
}
.confirm-message {
color: rgb(200,250,200);
}
.confirm-icon {
background-color: rgba(0,150,0,1);
}
/*-- bubble construction */
.bubble-part {
border-radius: 50%;
position: absolute;
}
.bubble {
background-color: rgba(50,50,100,0.1);
}
.soft-light {
background: radial-gradient(rgba(255,255,255,0.3),
rgba(255,255,255,0.1), rgba(255,255,255,0));
}
.mid-light {
background: radial-gradient(rgba(255,255,255,0.4),
rgba(255,255,255,0.1), rgba(255,255,255,0));
transform: rotateZ(-30deg);
}
.hard-light {
background: radial-gradient(rgba(255,255,255,0.4),
rgba(255,255,255,0.4));
transform: rotateZ(-30deg);
}
.base-light {
top: 3%;
left: 3%;
width: 94%;
height: 94%;
}
.top-light {
top: 10%;
left: 15%;
width: 40%;
height: 30%;
}
.bottom-light {
width: 60%;
height: 50%;
top: 40%;
left: 35%;
transform: rotateZ(-40deg);
}
.off-light-1 {
width: 6%;
height: 6%;
top: 35%;
left: 30%;
}
.off-light-2 {
width: 10%;
height: 10%;
top: 50%;
left: 25%;
opacity: 0.8;
}
/*--bubble animation*/
@keyframes bubbleRise {
from {
top: 100%;
}
to {
top: -20%;
}
}
var baseFunc = {
getRandomInt: function(min, max) {
//get random integer between a specific range
//Source - Ionuț G. Stan - StackOverflow - Answer 06/10/09
return Math.floor(Math.random() * (max - min + 1)) + min;
},
addClass: function(element, classesToAdd) {
//add a class or multiple classes to an element
var newClassName = element.className.trim().replace(/\s+/g,' ') + ' ';
var newClasses = classesToAdd.split(/\s+/);
var len = newClasses.length;
var ind = 0;
while(ind < len) {
var testTerm = new RegExp(newClasses[ind] + ' ');
if (!testTerm.test(newClassName)) {
//current className doesn't contain class - add it
newClassName += newClasses[ind] + ' ';
}
ind++;
}
element.className = newClassName.trim();
},
removeClass: function(element, classesToRemove) {
//remove a class or multiple classes from an element
var newClass = element.className.trim().replace(/\s+/g,' ') + ' ';
var classes = classesToRemove.split(/\s+/);
var ind = classes.length;
while(ind--) {
//remove class
newClass = newClass.replace(classes[ind] + ' ','');
}
element.className = newClass.trim();
}
};
var showBox = function(box) {
baseFunc.addClass(box, "active-box");
};
var hideBox = function(box) {
baseFunc.removeClass(box, "active-box");
};
var showMessage = function(message, messageType) {
var messageBox = document.getElementById("message-box");
var messageLine = document.getElementById("message-line");
var messageIcon = document.getElementById("message-icon");
var messageText = document.getElementById("message-text");
var messageButton = document.getElementById("message-button");
messageText.innerHTML = message;
if (messageType === "error") {
messageBox.className = "box message-box error-message";
messageIcon.className = "error-icon";
messageIcon.innerHTML = "!";
} else if (messageType === "confirm" ) {
messageBox.className = "box message-box confirm-message";
messageIcon.className = "confirm-icon";
messageIcon.innerHTML = "i";
}
messageButton.onclick = function() {
hideBox(messageBox);
};
showBox(messageBox);
};
var animakuzBubbles = function() {
var btnGenerate = document.getElementById("btn-generate");
var btnShowOptions = document.getElementById("btn-show-options");
var btnHideOptions = document.getElementById("btn-hide-options");
var bubbles = [];
var createBubble = function(duration, delay, depth, size, pos) {
var bubble = document.createElement("div");
var baseLight = '<div class="soft-light base-light bubble-part"></div>';
var topLight = '<div class="mid-light top-light bubble-part"></div>';
var bottomLight = '<div class="mid-light bottom-light bubble-part"></div>';
var offLight1 = '<div class="hard-light off-light-1 bubble-part"></div>';
var offLight2 = '<div class="hard-light off-light-2 bubble-part"></div>';
//bubble properties
baseFunc.addClass(bubble, "bubble bubble-part");
bubble.style.width = size + "px";
bubble.style.height = size + "px";
bubble.style.top = "100%";
bubble.style.left = pos + "%";
bubble.style.opacity = depth / 100;
//inner parts
bubble.innerHTML = baseLight + topLight + bottomLight +
offLight1 + offLight2;
//animation
bubble.style.animationName = "bubbleRise";
bubble.style.animationDuration = duration + "s";
bubble.style.animationDelay = delay + "s";
bubble.style.animationIterationCount = "infinite";
return bubble;
};
var clearBubbles = function() {
//clear bubbles alredy present
var container = document.getElementById("bubble-container");
var len = bubbles.length;
while(len--) {
container.removeChild(bubbles[len]);
}
bubbles = [];
};
var generateBubbles = function(density) {
var container = document.getElementById("bubble-container");
var i;
//limits
var maxDuration = 10;
var minDuration = 5;
var maxDelay = 10;
var minDelay = 1;
var maxDepth = 10;
var minDepth = 100;
var maxSize = 100;
var minSize = 20;
var maxPos = 100;
var minPos = 1;
//bubble properties
var bubbleDuration;
var bubbleDelay;
var bubbleDepth;
var bubbleSize;
var bubblePos;
clearBubbles();
for (i=0; i<density; i++) {
bubbleDuration = baseFunc.getRandomInt(minDuration, maxDuration);
bubbleDelay = baseFunc.getRandomInt(minDelay, maxDelay);
bubbleDepth = baseFunc.getRandomInt(minDepth, maxDepth);
bubbleSize = baseFunc.getRandomInt(minSize, maxSize);
bubblePos = baseFunc.getRandomInt(minPos, maxPos);
bubbles.push(createBubble(bubbleDuration, bubbleDelay, bubbleDepth, bubbleSize, bubblePos));
container.appendChild(bubbles[i]);
}
};
btnGenerate.onclick = function() {
//generate button click
var txtBubbleDensity = document.getElementById("txt-bubble-density");
var density = txtBubbleDensity.value;
if (isNaN(density) || Number(density) <= 0) {
//show error
showMessage("Please enter a valid number!", "error");
} else {
//generate bubbles
generateBubbles(density);
}
};
btnShowOptions.onclick = function() {
//show options button click
var optionsBox = document.getElementById("options");
showBox(optionsBox);
btnShowOptions.style.display = "none";
};
btnHideOptions.onclick = function() {
//close button on options box
var optionsBox = document.getElementById("options");
hideBox(optionsBox);
btnShowOptions.style.display = "block";
};
generateBubbles(20);
};
animakuzBubbles();
Also see: Tab Triggers