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 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.
<h2>Adding bezier curve eases to GSAP</h2>
<div class='foo'>
<div class='bar' id='easeNone'>linear</div>
<div class='bar' id='easeIn'>ease-in</div>
<div class='bar' id='easeInOut'>ease-in-out</div>
<div class='bar' id='easeOut'>ease-out</div>
<div class='bar' id='ease'>ease</div>
<div class='bar' id='customEase'>(.2, .7, .8, .3)</div>
</div>
.foo {
margin: 20px;
width: 390px;
border-left: 1px solid #000;
border-right: 1px solid #000;
}
.bar {
position: relative;
width: 90px;
height: 90px;
background-color: #91E600;
border-radius: 50%;
line-height: 90px;
text-align: center;
white-space: pre;
}
h2 {
margin: 20px;
}
// (tweens at bottom)
/**
* BezierEasing - use bezier curve for transition easing function
* is based on Firefox's nsSMILKeySpline.cpp
* Usage:
* var spline = BezierEasing(0.25, 0.1, 0.25, 1.0)
* spline(x) => returns the easing value | x must be in [0, 1] range
*
* bezier-easing 0.4.0
* BSD License
* Gaëtan Renaudeau
* https://github.com/gre/bezier-easing
*/
(function (definition) {
if (typeof exports === "object") {
module.exports = definition();
}
else if (typeof window.define === 'function' && window.define.amd) {
window.define([], definition);
} else {
window.BezierEasing = definition();
}
}(function () {
// These values are established by empiricism with tests (tradeoff: performance VS precision)
var NEWTON_ITERATIONS = 4;
var NEWTON_MIN_SLOPE = 0.001;
var SUBDIVISION_PRECISION = 0.0000001;
var SUBDIVISION_MAX_ITERATIONS = 10;
var kSplineTableSize = 11;
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
var float32ArraySupported = typeof Float32Array === "function";
function BezierEasing (mX1, mY1, mX2, mY2) {
// Validate arguments
if (arguments.length !== 4) {
throw new Error("BezierEasing requires 4 arguments.");
}
for (var i=0; i<4; ++i) {
if (typeof arguments[i] !== "number" || isNaN(arguments[i]) || !isFinite(arguments[i])) {
throw new Error("BezierEasing arguments should be integers.");
}
}
if (mX1 < 0 || mX1 > 1 || mX2 < 0 || mX2 > 1) {
throw new Error("BezierEasing x values must be in [0, 1] range.");
}
var mSampleValues = float32ArraySupported ? new Float32Array(kSplineTableSize) : new Array(kSplineTableSize);
function A (aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1; }
function B (aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1; }
function C (aA1) { return 3.0 * aA1; }
// Returns x(t) given t, x1, and x2, or y(t) given t, y1, and y2.
function calcBezier (aT, aA1, aA2) {
return ((A(aA1, aA2)*aT + B(aA1, aA2))*aT + C(aA1))*aT;
}
// Returns dx/dt given t, x1, and x2, or dy/dt given t, y1, and y2.
function getSlope (aT, aA1, aA2) {
return 3.0 * A(aA1, aA2)*aT*aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
}
function newtonRaphsonIterate (aX, aGuessT) {
for (var i = 0; i < NEWTON_ITERATIONS; ++i) {
var currentSlope = getSlope(aGuessT, mX1, mX2);
if (currentSlope === 0.0) return aGuessT;
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
aGuessT -= currentX / currentSlope;
}
return aGuessT;
}
function calcSampleValues () {
for (var i = 0; i < kSplineTableSize; ++i) {
mSampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
}
}
function binarySubdivide (aX, aA, aB) {
var currentX, currentT, i = 0;
do {
currentT = aA + (aB - aA) / 2.0;
currentX = calcBezier(currentT, mX1, mX2) - aX;
if (currentX > 0.0) {
aB = currentT;
} else {
aA = currentT;
}
} while (Math.abs(currentX) > SUBDIVISION_PRECISION && ++i < SUBDIVISION_MAX_ITERATIONS);
return currentT;
}
function getTForX (aX) {
var intervalStart = 0.0;
var currentSample = 1;
var lastSample = kSplineTableSize - 1;
for (; currentSample != lastSample && mSampleValues[currentSample] <= aX; ++currentSample) {
intervalStart += kSampleStepSize;
}
--currentSample;
// Interpolate to provide an initial guess for t
var dist = (aX - mSampleValues[currentSample]) / (mSampleValues[currentSample+1] - mSampleValues[currentSample]);
var guessForT = intervalStart + dist * kSampleStepSize;
var initialSlope = getSlope(guessForT, mX1, mX2);
if (initialSlope >= NEWTON_MIN_SLOPE) {
return newtonRaphsonIterate(aX, guessForT);
} else if (initialSlope == 0.0) {
return guessForT;
} else {
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize);
}
}
if (mX1 != mY1 || mX2 != mY2)
calcSampleValues();
var f = function (aX) {
if (mX1 === mY1 && mX2 === mY2) return aX; // linear
// Because JavaScript number are imprecise, we should guarantee the extremes are right.
if (aX === 0) return 0;
if (aX === 1) return 1;
return calcBezier(getTForX(aX), mY1, mY2);
};
var str = "BezierEasing("+[mX1, mY1, mX2, mY2]+")";
f.toString = function () { return str; };
return f;
}
// CSS mapping
BezierEasing.css = {
"ease": BezierEasing(0.25, 0.1, 0.25, 1.0),
"linear": BezierEasing(0.00, 0.0, 1.00, 1.0),
"ease-in": BezierEasing(0.42, 0.0, 1.00, 1.0),
"ease-out": BezierEasing(0.00, 0.0, 0.58, 1.0),
"ease-in-out": BezierEasing(0.42, 0.0, 0.58, 1.0)
};
return BezierEasing;
}));
// create Bezier object to match GSAP syntax
BezierCurve = {
ease: new Ease(BezierEasing.css["ease"]),
easeNone: new Ease(BezierEasing.css["linear"]),
easeIn: new Ease(BezierEasing.css["ease-in"]),
easeOut: new Ease(BezierEasing.css["ease-out"]),
easeInOut: new Ease(BezierEasing.css["ease-in-out"])
};
var tl = new TimelineMax({ onComplete: function() {
// rewind
TweenLite.to(this.pause(), 1, { time: 0, onComplete: this.resume, onCompleteScope: this });
} });
tl.to("#easeNone", 4, {
x:300, force3D:true,
ease:BezierCurve.easeNone
}, 1)
.to("#easeIn", 4, {
x:300, force3D:true,
ease:BezierCurve.easeIn
}, 1)
.to("#easeInOut", 4, {
x:300, force3D:true,
ease:BezierCurve.easeInOut
}, 1)
.to("#easeOut", 4, {
x:300, force3D:true,
ease:BezierCurve.easeOut
}, 1)
.to("#ease", 4, {
x:300, force3D:true,
ease:BezierCurve.ease
}, 1)
.to("#customEase", 4, {
x:300, force3D:true,
ease:new Ease(BezierEasing(0.2, 0.7, 0.8, 0.3))
}, 1)
.set({}, {}, "+=1"); // just 1 second padding before rewind
Also see: Tab Triggers