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 href="http://davidwalsh.name/" id="logo">David Walsh Blog</a>
#logo {
width: 300px;
height: 233px;
overflow: hidden;
display: block;
background-position: 0 0;
background-repeat: no-repeat;
text-indent: -9000px;
}
#logo span {
float: left;
display: block;
}
#logo, #logo span {
background-image: url(http://davidwalsh.name/wp-content/themes/2k11/images/homeLogo.png);
}
/*
Demo created by David Walsh
http://davidwalsh.name
Uses CSS Animation library by Ryan Florence
http://ryanflorence.com
*/
(function(global) {
// console.log(global);
// Outputs window
var getSupportedStyle = function(element, supported){
for (var i = supported.length - 1; i >= 0; i--){
if (element.style[supported[i]] !== undefined){
return supported[i];
}
};
};
var Transform = global.Transform = function(element, supported){
this.element = element;
this.style = getSupportedStyle(element, supported || [ 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform' ]);
}; global.Transform.prototype = {
translate: function(axis, value){
return this.setter(axis, value, 'translate');
},
rotate: function(axis, value){
if (typeof axis === 'number') return this.add('rotate', axis);
return this.setter(axis, value, 'rotate');
},
skew: function(axis, value){
return this.setter(axis, value, 'skew');
},
scale: function(axis, value){
if (typeof axis === 'number') return this.add('scale', axis);
this.setter(axis, value, 'scale');
return this;
},
matrix: function(){
var transform = this.element.style[this.style],
match = new RegExp(this.rules.matrix.regex).test(transform),
shared = 'matrix(' + Array.prototype.slice.call(arguments, 0).join(',') + ')';
if (transform === 'none') transform = '';
return match
? this.set(transform.replace(this.rules[rule].regex, shared))
: this.set(transform + ' ' + shared);
},
clear: function(){
return this.set('');
},
set: function(def){
this.element.style[this.style] = def;
return this;
},
// not "public", feel free to use, but the rest of these methods
// are not guaranteed to have backward compatibility in future releases
setter: function(a, b, method){
if (typeof a === 'string') return this.add(method + a.toUpperCase(), b);
for (i in a) if (a.hasOwnProperty(i)) this[method](i, a[i])
return this;
},
add: function(rule, value){
var transform = this.element.style[this.style],
rule = rule === 'rotateZ' ? 'rotate' : rule,
match = new RegExp(this.rules[rule].regex).test(transform),
unit = this.rules[rule].unit,
shared = rule + '(' + value + unit + ')';
if (transform === 'none') transform = '';
return match
? this.set(transform.replace(this.rules[rule].regex, shared))
: this.set(transform + ' ' + shared);
},
remove: function(rule){
return this.set(this.element.style[this.style].replace(this.rules[rule].regex, ''));
},
// this is admittadly verbose, but if an API changes,
// this is easy to override and (sortof) future-proof the script
// I'm still not sold it's the right way :\ ... but I'm more interested in
// creating something useful first, then clean it up :D
rules: {
'rotateX':{
regex: /rotateX\((-?[0-9]+deg)\)/,
unit: 'deg'
},
'rotateY': {
regex: /rotateY\((-?[0-9]+deg)\)/,
unit: 'deg'
},
'rotateZ': {
regex: /rotateZ\((-?[0-9]+deg)\)/,
unit: 'deg'
},
'rotate': {
regex: /rotate\((-?[0-9]+deg)\)/,
unit: 'deg'
},
'translateX': {
regex: /translateX\((-?[0-9]+%)\)/,
unit: '%'
},
'translateY': {
regex: /translateY\((-?[0-9]+%)\)/,
unit: '%'
},
'translateZ': {
regex: /translateZ\((-?[0-9]+px)\)/,
unit: 'px'
},
'scale': {
regex: /scale\((-?[0-9]+)\)/,
unit: ''
},
'scaleX': {
regex: /scaleX\((-?[0-9]+)\)/,
unit: ''
},
'scaleY': {
regex: /scaleY\((-?[0-9]+)\)/,
unit: ''
},
'skewX': {
regex: /skewX\((-?[0-9]+deg)\)/,
unit: 'deg'
},
'skewY': {
regex: /skewY\((-?[0-9]+deg)\)/,
unit: 'deg'
},
'scale': {
regex: /scale\((-?[0-9]+\.?[0-9]+?)\)/,
unit: ''
},
'scaleX': {
regex: /scaleX\((-?[0-9]+\.?[0-9]+?)\)/,
unit: ''
},
'scaleY': {
regex: /scaleY\((-?[0-9]+\.?[0-9]+?)\)/,
unit: ''
},
'matrix': {
regex: /matrix(.+)/,
unit: ''
}
}
};
var Transition = global.Transition = function(element, supported){
this.element = element;
this.supported = supported || {
prefixes: ['WebkitTransition', 'MozTransition', 'OTransition', 'msTransition' ],
transformPrefixes: ['-webkit-' , '-moz-' , '-o-' , '-ms-']
};
this.style = getSupportedStyle(element, this.supported.prefixes);
this.supported.index = this.supported.prefixes.indexOf(this.style);
}; global.Transition.prototype = {
map: {
'duration': 'Duration',
'property': 'Property',
'timing-function': 'TimingFunction'
},
set: function(property, value){
if (typeof property === 'string') {
if (value === 'transform') value = this.supported.transformPrefixes[this.supported.index] + 'transform';
this.element.style[this.style + this.map[property]] = value;
return this;
}
for (i in property) if (property.hasOwnProperty(i)) this.set(i, property[i]);
return this;
},
clear: function(rule){
if (!rule) {
return this.set({
duration: '',
property: '',
'timing-function': ''
});
}
return this.set(rule, '');
}
}
})(window); // change window to whatever global object you want to hand these constructors from
/*
---
name: Transform.MooTools
license: MIT-style license.
author: Ryan Florence <http://ryanflorence.com>
requires:
- Core/Element
- CSSAnimation
provides: [MooTools]
...
*/
Element.Properties.transform = {
set: function(supported){
return this.store('transform', new Transform(this, supported));
},
get: function(){
var instance = this.retrieve('transform');
return instance || this.set('transform').get('transform');
}
};
Element.Properties.transition = {
set: function(supported){
return this.store('transition', new Transition(this, supported));
},
get: function(){
var instance = this.retrieve('transition');
return instance || this.set('transition').get('transition');
}
};
(function(){
var obj = {};
['translate', 'rotate', 'scale', 'skew', 'matrix'].each(function(method){
obj[method] = function(){
var instance = this.get('transform');
instance[method].apply(instance, Array.slice(arguments, 0));
return this;
};
});
obj.trans = obj.translate;
obj.clearTransform = function(){
this.get('transform').clear();
return this;
};
['set', 'clear'].each(function(method){
obj[method + 'Transition'] = function(){
var instance = this.get('transition');
instance[method].apply(instance, Array.slice(arguments, 0));
return this;
}
});
Element.implement(obj);
}());
// reset transforms to this
var zeros = {x:0, y:0, z:0};
// Implement animation methods on the element prototype
Element.implement({
// Scatter elements all over the place
scatter: function(){
return $(this).trans({
x: Number.random(-1000, 1000),
y: Number.random(-1000, 1000),
z: Number.random(-500, 500)
}).rotate({
x: Number.random(-720, 720),
y: Number.random(-720, 720),
z: Number.random(-720, 720)
});
},
// Return them to their original state
unscatter: function(){
return $(this).trans(zeros).rotate(zeros);
},
// Frighten the image! AHHHHHHHH!
frighten: function(d){
this.setTransition('timing-function', 'ease-out').scatter();
setTimeout(function(){
this.setTransition('timing-function', 'ease-in-out').unscatter();
}.bind(this), 500);
return this;
},
// Zoooooom into me
zoom: function(delay){
var self = this;
this.scale(0.01);
setTimeout(function(){
self.setTransition({
property: 'transform',
duration: '250ms',
'timing-function': 'ease-out'
}).scale(1.2);
setTimeout(function(){
self.setTransition('duration', '100ms').scale(1);
}, 250)
}, delay);
},
// Create a slider
makeSlider: function(){
var open = false,
next = this.getNext(),
height = next.getScrollSize().y,
transition = {
property: 'height',
duration: '500ms',
transition: 'ease-out'
};
next.setTransition(transition);
this.addEvent('click', function(){
next.setStyle('height', open ? 0 : height);
open = !open;
});
},
// Scatter, come back
fromChaos: (function(x){
var delay = 0;
return function(){
var element = this;
//element.scatter();
setTimeout(function(){
element.setTransition({
property: 'transform',
duration: '500ms',
'timing-function': 'ease-out'
});
setTimeout(function(){
element.unscatter();
element.addEvents({
mouseenter: element.frighten.bind(element),
touchstart: element.frighten.bind(element)
});
}, delay += x);
}, x);
}
}())
});
// Get the proper CSS prefix from the page
var cssPrefix = false;
switch(Browser.name) { // Implement only for Chrome, Firefox, and Safari
case "safari":
case "chrome":
cssPrefix = "webkit";
break;
case "firefox":
cssPrefix = "moz";
break;
}
// If we support this browser....
if(cssPrefix) {
// 300 x 233
var cols = 20; // Desired columns
var rows = 16; // Desired rows
var totalWidth = 300; // Logo width
var totalHeight = 233; // Logo height
var singleWidth = Math.ceil(totalWidth / cols); // Shard width
var singleHeight = Math.ceil(totalHeight / rows); // Shard height
var shards = []; // Array of SPANs
// Remove the text and background image from the logo
var logo = document.id("logo").set("html","").setStyles({ backgroundImage: "none" });
// For every desired row
rows.times(function(rowIndex) {
// For every desired column
cols.times(function(colIndex) {
// Create a SPAN element with the proper CSS settings
// Width, height, browser-specific CSS
var element = new Element("span",{
style: "width:" + (singleWidth) + "px;height:" + (singleHeight) + "px;background-position:-" + (singleHeight * colIndex) + "px -" + (singleWidth * rowIndex) + "px;-" + cssPrefix + "-transition-property: -" + cssPrefix + "-transform; -" + cssPrefix + "-transition-duration: 200ms; -" + cssPrefix + "-transition-timing-function: ease-out; -" + cssPrefix + "-transform: translateX(0%) translateY(0%) translateZ(0px) rotateX(0deg) rotateY(0deg) rotate(0deg);"
}).inject(logo);
// Save it
shards.push(element);
});
});
// Chaos!
$$(shards).fromChaos(1000);
// console.log($$(shards).fromChaos(1000));
// Didn't know what this was with domready
}
Also see: Tab Triggers