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 URL's added here will be added as <link>
s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.
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.
If the stylesheet 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 CSS 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.
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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<!-- Nothing here required for app -->
<span>
<p><b><i>Following Eyes</i></b></p>
</span>
/* Nothing here required for app */
html{
height:100%;
}
body{
background-color:#bfc51e;
margin:0px;
text-align: center;
}
sup{
font-size: 55%;
}
span{
display:inline-block;
position:relative;
margin:10px;
padding:4px;
width:300px;
line-height: 18px;
user-select: none;
-moz-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
cursor: default;
background-color:#ee0000;
border-radius:5px;
font: 26px verdana;
color: #fff;
text-align: center;
}
p {
margin: 5px;
}
(function () {
/* Following Eyes - kurt.grigg@yahoo.co.uk 2003 (Updated) */
var eye = 50; //Eye size in pixels
if (eye % 2 == 0){
eye++;
}
var eye5 = eye / 2 | 0;
var pup = 42 * eye / 100;
if (pup % 2 == 0){
pup++;
}
var pup5 = (pup - 3) / 2;
if (pup5 % 2 == 1){
pup5++;
}
var grng = (eye - pup) / 2;
if (grng % 2 == 1){
grng++;
}
var rng = eye5 / grng;
var d = document;
var my = 0;
var mx = 0;
var fy = 0;
var fx = 0;
var ros = eye + 2;
var rim = 0.25 * eye / 100;
var scy = 0;
var scx = 0;
var pix = 'px';
var mls = 1000 / 60;
var lastEx = performance.now();
var h, w;
var cstyle =
'position:absolute;top:0px;left:0px;width:'+(ros*2)+'px;height:'+ros+'px;'
+'line-height:0px;margin:0px;border:none;padding:0px;display:inline-block;';
var estyle =
'position:absolute;top:0px;left:0px;height:'+eye+'px;'
+'width:'+eye+'px;line-height:0px;background-color:#fff;'
+'border-radius: 50%;border:'+rim+'px solid #888;'
+'box-shadow: inset -'+eye/3+'px -'+eye/3+'px '+eye/2+
'px -'+(eye/10|0)+'px rgba(0,0,0,0.16);';
var pstyle =
'position:absolute;top:45%;left:45%;height:'+pup+'px;'
+'width:'+pup+'px;line-height:0px;border-radius: 50%;background-color:#222;';
var shine = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 145 145"><g><ellipse cx="0" cy="-50" fill="#fff" transform="rotate(135)" ry="9.464" rx="21.25"/></g></svg>';
var c = d.createElement('div');
var e1 = d.createElement('div');
var e2 = d.createElement('div');
var p1 = d.createElement('div');
var p2 = d.createElement('div');
c.setAttribute('style', cstyle);
e1.setAttribute('style', estyle);
e2.setAttribute('style', estyle + 'left:'+(ros + (rim/2))+'px;');
p1.setAttribute('style', pstyle);
p2.setAttribute('style', pstyle);
p1.innerHTML = shine;
p2.innerHTML = shine;
d.body.appendChild(c);
c.appendChild(e1);
c.appendChild(e2);
d.body.appendChild(p1);
d.body.appendChild(p2);
function scrl(v) {
var y, x;
y = window.pageYOffset;
x = window.pageXOffset;
return (v == 0) ? y : x;
}
function initscroll() {
scy = scrl(0);
scx = scrl(1);
}
function windims() {
var ddw = d.documentElement.clientWidth;
var ddh = d.documentElement.clientHeight;
var scrollBarRight = (typeof ddw == 'number') ? window.innerWidth - ddw : 0;
var scrollBarBottom = (typeof ddh == 'number') ? window.innerHeight - ddh : 0;
h = window.innerHeight - scrollBarBottom -1;
w = window.innerWidth - scrollBarRight -1;
}
function mouse(e) {
if (!e) {
e = window.event;
}
my = e.pageY - window.pageYOffset;
mx = e.pageX - window.pageXOffset;
}
function ani() {
//Keep eyes on screen.
var chy = Math.floor(fy - (ros*1.2));
if (chy <= 0) {
chy = 0;
}
if (chy >= h - ros) {
chy = h - ros;
}
var chx = Math.floor(fx - ros);
if (chx <= 0) {
chx = 0;
}
if (chx >= w - (ros*2)) {
chx = w - (ros*2);
}
//Eyeball centres.
var yec = chy + eye5;
var xec = chx + eye5;
var d1 = Math.sqrt((my - yec) * (my - yec) + (mx - xec) * (mx - xec));
var d2 = Math.sqrt((my - yec) * (my - yec) + (mx - (xec + ros)) * (mx - (xec + ros)));
var a1 = Math.atan2(my - yec, mx - xec) * 180 / Math.PI;
var a2 = Math.atan2(my - yec, mx - (xec + ros)) * 180 / Math.PI;
var le = (d1 < eye5) ? d1 / rng : grng;
var re = (d2 < eye5) ? d2 / rng : grng;
c.style.top = chy + scy + pix;
c.style.left = chx + scx + pix;
p1.style.top = yec - pup5 + le * Math.sin(a1 * Math.PI / 180) + scy + pix;
p1.style.left = xec - pup5 + le * Math.cos(a1 * Math.PI / 180) + scx + pix;
p2.style.top = yec - pup5 + re * Math.sin(a2 * Math.PI / 180) + scy + pix;
p2.style.left = (xec + ros) - pup5 + re * Math.cos(a2 * Math.PI / 180) + scx + pix;
}
function move() {
var dy = fy += (my - fy) * 0.05;
var dx = fx += (mx - fx) * 0.05;
ani();
}
function init() {
windims();
draw();
}
function draw() {
var now = performance.now();
if ((now - lastEx) > (mls)) {
move();
lastEx = performance.now();
}
requestAnimationFrame(draw);
}
window.addEventListener("resize", windims, false);
window.addEventListener("load", init, false);
d.addEventListener("mousemove", mouse, false);
window.addEventListener("scroll", initscroll, false);
})();
Also see: Tab Triggers