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.
<!--
I got the SVG image from:
* https://commons.wikimedia.org/wiki/File:Milky_way_stargate_with_very_detailed_glyphs2.svg
* Author: Max Willis & User:M.A.D.company
* I split the image up into separate parts:
- The outer edge
- The ring that rotates
- each Chevron
Videos of stargate dialing:
* https://www.youtube.com/watch?v=B8JoShAUE1U
* https://www.youtube.com/watch?v=3Ds0DRCNXN4
Info about how stargates are "supposed" to work:
* https://en.wikipedia.org/wiki/Stargate_(device)
- Six or more symbols must be dialed in a specific order
to establish a wormhole with another desired gate
-->
Attribution: See HTML comments for information.
<div id="info"></div>
<div id="stargateContainer">
<img id="symbols" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateSymbols.svg">
<img id="outerEdge" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateOuterEdge.svg">
<img id="chevron1" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron1.svg">
<img id="chevron2" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron2.svg">
<img id="chevron3" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron3.svg">
<img id="chevron4" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron4.svg">
<img id="chevron5" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron5.svg">
<img id="chevron6" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron6.svg">
<img id="chevron7" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron7.svg">
<img id="chevron8" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron8.svg">
<img id="chevron9" class="stargate" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/1658514/stargateChevron9.svg">
<div id="penTitle">#codePenChallenge</div>
</div>
<div id="standAloneLink">
<a href="/orvilleChomer/debug/yvWmGY" target="_new">Stand-alone Window</a>
</div>
<style id="animationStyles"></style>
body {
background:#212121;
}
#stargateContainer {
position:absolute;
left:30px;
top:60px;
z-index:210;
transform-origin:0 0;
}
.stargate {
position:absolute;
left:0px;
top:0px;
width:528px;
height:526px;
z-index:100;
}
.attribBtn {
position:absolute;
left:5px;
top:5px;
}
#standAloneLink {
display:none;
}
a {
color:white;
font-family: "Lato", "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif;
}
#penTitle {
font-family: "Lato", "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif;
position:absolute;
top:240px;
left:85px;
width:354px;
height:90px;
overflow:hidden;
font-family:Lucida Console;
font-size:25pt;
font-weight:bold;
color:orange;
text-align:center;
}
#info {
position:absolute;
top:30px;
left:120px;
}
var stargate ={};
pageSetup();
function pageSetup() {
var info = $("#info")[0];
var standAloneLink = $("#standAloneLink")[0];
var stargateContainer = $("#stargateContainer")[0];
var outerEdge = $("#outerEdge")[0];
var s=[];
var nScale;
var sScale;
stargate.currentRotationDir = "clockwise";
// color codes
stargate.chevronColorNotLit = "";
stargate.chevronColorLit = "";
stargate.degreesPerSymbol = 360 / 39; // there are 39 symbols
stargate.classCounter = 0;
stargate.currentGateAngle = 0;
stargate.currentSymbolIndex = 0;
stargate.width = 700;
stargate.animationIdx = -1;
stargate.animationsByIndex = [];
console.log("");
stargate.addAnimation = function(sType, optParams) {
var ani = {};
var nMax = stargate.animationsByIndex.length;
ani.animationType = sType;
ani.idx = nMax;
ani.optParams = optParams;
stargate.animationsByIndex[nMax] = ani;
} // end of method stargate.addAnimation()
if(document.location.href.indexOf("debug")<0) {
standAloneLink.style.display = "block";
} // end if
if (stargate.width > (window.innerWidth)) {
sScale = "scale(0.72)";
stargateContainer.style.left = "15px";
stargateContainer.style.transform = sScale;
} // end if
stargate.addAnimation("dialSymbol",{"num":5});
//stargate.addAnimation("activateChevron",{"num":1,"xOffset":0,"yOffset":20});
stargate.addAnimation("dialSymbol",{"num":35});
stargate.addAnimation("dialSymbol",{"num":23});
stargate.addAnimation("dialSymbol",{"num":4});
stargate.addAnimation("dialSymbol",{"num":8});
stargate.addAnimation("dialSymbol",{"num":14});
stargate.addAnimation("updateCenterCaption",{"caption":"Engaging<br>7th Symbol"});
stargate.addAnimation("dialSymbol",{"num":8});
stargate.addAnimation("updateCenterCaption",{"caption":""});
console.log("Animations added");
runNextAnimation();
} // end of function pageSetup()
function runNextAnimation() {
console.log("runNextAnimation() called");
var nMax = stargate.animationsByIndex.length;
var ani,optParams;
if (stargate.animationIdx === nMax-1) {
return; // done running animations
} // end if
stargate.performingAnimation = true;
stargate.animationIdx = stargate.animationIdx + 1;
ani = stargate.animationsByIndex[stargate.animationIdx];
optParams = ani.optParams;
switch(ani.animationType) {
case "dialSymbol":
dialSymbolNum(optParams.num);
break;
case "activateChevron":
doChevronAnimation(optParams.num,
optParams.xOffset,
optParams.yOffset);
break;
case "updateCenterCaption":
updateCenterCaption(optParams);
runNextAnimation();
break;
} // end of switch(ani.animationType)
} // end of function
function animationComplete() {
console.log("animationComplete() called");
stargate.performingAnimation = false;
runNextAnimation();
} // end of function animationComplete()
function crazyRounding(nNum, nPrecision) {
var sNum = nNum+"";
var nPos = sNum.indexOf(".");
var nLen = sNum.length;
var nLastDigit,nCheckDigit;
if (typeof nPrecision === "undefined") {
nPrecision = 3; // inferred precision if none is provided
} // end if
if (nPos===-1 || nPos > nLen-nPrecision) {
return nNum; // no need to round
} // end if
nLastDigit = (sNum.substr(nPos+nPrecision,1))-0;
nCheckDigit = (sNum.substr(nPos+nPrecision+1,1))-0;
if (nCheckDigit > 5) {
nLastDigit = nLastDigit + 1; // round up
} // end if
sNum = sNum.substr(0,nPos+nPrecision) + nLastDigit;
nNum = sNum - 0;
return nNum;
} // end of function crazyRounding(()
function dialSymbolNum(nIdx) {
console.log("dialSymbolNum() called");
var nIndexSymbolAngle = stargate.degreesPerSymbol * nIdx;
var nStartAngle = stargate.currentGateAngle;
var nEndAngle,nOffset;
var sRotation = stargate.currentRotationDir;
if (sRotation === "clockwise") {
if (nIndexSymbolAngle < nStartAngle) {
nOffset = nStartAngle - nIndexSymbolAngle;
// instead of going backwards, go all the way
// around (minus the offset):
nEndAngle = nStartAngle + 360 - nOffset;
doRotateGateAnimation(nEndAngle);
return;
} // end if
if (nIndexSymbolAngle === nStartAngle) {
// same spot as before? Boring!
// go around twice (to make things a little interesting):
nEndAngle = nStartAngle + 360 * 2;
doRotateGateAnimation(nEndAngle);
return;
} // end if
if (nIndexSymbolAngle > nStartAngle) {
nOffset = nIndexSymbolAngle - nStartAngle;
nEndAngle = nIndexSymbolAngle; // just move clockwise to the desired symbol
//unless...
if (nOffset < 181) {
// too small of a change... we want more movement!
nEndAngle = nEndAngle + 360;
} // end if
doRotateGateAnimation(nEndAngle);
return;
} // end if
} else {
// counter-clockwise...
if (nIndexSymbolAngle > nStartAngle) {
nOffset = nIndexSymbolAngle - nStartAngle;
// instead of going forwards, go all the way
// around (plus the offset):
nEndAngle = nStartAngle - 360 + nOffset;
doRotateGateAnimation(nEndAngle);
} // end if (nIndexSymbolAngle > nStartAngle)
if (nIndexSymbolAngle === nStartAngle) {
// same spot as before? Boring!
// go around twice (to make things a little interesting):
nEndAngle = nStartAngle - 360 * 2;
doRotateGateAnimation(nEndAngle);
return;
} // end if (nIndexSymbolAngle === nStartAngle)
if (nIndexSymbolAngle < nStartAngle) {
nOffset = nStartAngle - nIndexSymbolAngle;
nEndAngle = nIndexSymbolAngle; // just move cntr clockwise to the desired symbol
if (nOffset > 180) {
// too small of a change... we want more movement!
nEndAngle = nEndAngle - 360;
} // end if (nOffset > 180)
doRotateGateAnimation(nEndAngle);
return;
} // end if (nIndexSymbolAngle < nStartAngle)
} // end if/else
} // end of function dialSymbolNum()
function doRotateGateAnimation(nEndAngle) {
var sRotation = stargate.currentRotationDir;
var s =[];
var sClass = getAnimationClassName();
var symbols = $("#symbols")[0];
var animationStyles = $("#animationStyles")[0];
var nStartAngle;
var nSymbolAngle = 360 /39; // there are 39 symbols
nEndAngle = crazyRounding(nEndAngle);
nStartAngle = stargate.currentGateAngle;
s[s.length] = "@keyframes "+sClass+"KF {";
s[s.length] = " from {transform: translate(0px,1px) rotate("+nStartAngle+"deg) }";
s[s.length] = " to {transform: translate(0px,1px) rotate("+nEndAngle+"deg) };";
s[s.length] = "}";
s[s.length] = "";
s[s.length] = "."+sClass+" {";
s[s.length] = " animation-delay: .25s;";
s[s.length] = " animation-name:"+sClass+"KF;";
s[s.length] = " animation-duration:5s;";
s[s.length] = " animation-fill-mode: both;";
s[s.length] = "}";
animationStyles.innerHTML = s.join("\n");
symbols.addEventListener("animationend", runNextAnimation, false);
symbols.className = "stargate "+sClass;
toggleGateRotation();
} // end of function
function getAnimationClassName() {
stargate.classCounter++
if (stargate.classCounter > 100) {
stargate.classCounter = 1;
} // end if
return "aniCls"+stargate.classCounter;
} // end of function
function doEngageChevronAnimation() {
} // end of function
function doBlinkChevronAnimation() {
} // end of function
function toggleGateRotation() {
var sRotation = stargate.currentRotationDir;
if (sRotation === "clockwise") {
stargate.currentRotationDir = "counter-clockwise";
} else {
stargate.currentRotationDir = "clockwise";
} // end if/else
} // end of function
function showAttribution() {
var attribPanel = $("#attribPanel")[0];
attribPanel.style.display = "block";
return false;
} // end of function
Also see: Tab Triggers