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. You can use the CSS from another Pen by using it's URL and the proper URL extention.
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.
<div class="tlContainer clearfix">
<div class="tlContent">
<div class="tlBox red">
<p>1</p>
</div>
<div class="tlBox green">
<p>2</p>
</div>
<div class="tlBox blue">
<p>3</p>
</div>
<div class="tlBox red">
<p>4</p>
</div>
<div class="tlBox green">
<p>5</p>
</div>
<div class="tlBox blue">
<p>6</p>
</div>
<div class="tlBox red">
<p>7</p>
</div>
<div class="tlBox green">
<p>8</p>
</div>
<div class="tlBox blue">
<p>9</p>
</div>
</div>
</div>
<div id="sliderText">Use the slider to scroll through colored panels</div>
<div id="slider"></div>
<div id="debug"></div>
*{
box-sizing: border-box;
}
html,
body {
font-family: sans-serif;
margin: 0;
color: #888;
background: #2B2C2D;
/*overflow: hidden;*/
}
.tlContainer {
width: 90%;
height: 260px;
max-height: 360px;
background-color: white;
position: relative;
margin: 20px auto;
border: 1px solid #555;
/* toggle this on/off to see the start/end positions of the content div */
overflow: hidden;
}
.tlContent {
/* holder of the boxes */
/* \\ we don't need to to set a width \\ */
/*width: 12000px;*/
height: 100%;
/* \\ Uneccesary for relative position unless not 0 \\ */
/*top: 0;
left: 0;*/
position: relative;
/*border: 1px solid red;*/
/* \\ This is what will allow the contents to not wrap
\\ so our container can grow horizontally
*/
white-space: nowrap;
/* \\ Deals with spaces in the markup so they are not
\\ rendered as 4px gaps
*/
font-size: 0;
}
.tlBox {
/* Since the container's font-size is 0, let's reset here */
font-size: 13pt;
width: calc(33.3%);
height: 100%;
margin: 0 5px 0 0;
/* \\ Floating has a lot of inherent issues
\\ we'll go with inline-block' */
/*float: left;*/
display: inline-block;
vertical-align: top;
text-align: center;
color: #fff;
/*display: block;*/
border: 2px solid blue;
/* \\ Because the parent is set to nowrap, this inherits that
\\ we want the content of the tile to behave "normally" */
white-space: normal;
}
.red {
background-color: red;
}
.green {
background-color: green;
}
.blue {
background-color: blue;
}
/* #ctrl_slider {
width: 400px;
margin: 10px auto;
} */
#slider {
/* position:relative; */
width: 824px;
height:10px;
margin: 10px auto;
background: rgba(80,80,80,0.5);
border:1px solid rgba(102,102,102,0.5);
}
#sliderText {
text-align:center;
}
#debug div{
height: 50px;
background-color: #CCC;
margin: 15px;
}
// get width of boxes, and multiply by how many to set width of sliding container div.
var _boxesVis = 3;
// Include the 5px margin if the CSS is using one.
var _boxwidth = $('.tlBox').first().width() + 5 + 4; // +4 is because of the order width
var _boxCount = $('.tlBox').length;
var _tlInnerWidth = _boxwidth * _boxCount;
/* // We get the width of the masking div
*/
var _tlContainerWidth = $('.tlContainer').width();
/* // We now set the animate 'x' distance to be the width of all the tiles minus
// the width of the masking window so we don't animate into empty space
*/
var _animateWidth = (_tlInnerWidth - _tlContainerWidth) + 5; // +5 is to note animate to the last right margin
/* // We don't need to calculate this, CSS
// rules allow it to be set itself
*/
// set the container div width to the calculated _tlInnerWidth
//TweenLite.set(".tlContent", {width: _tlInnerWidth});
// Set an array of snapto points
var snapPoints = [];
var snapPointsCount = _boxCount-_boxesVis;
var snapInc = _boxwidth/_animateWidth;
console.log('snapInc: '+snapInc);
for(i=0;i<=snapPointsCount;i++){
snapPoints[i]= snapInc*i;
}
console.log(snapPoints);
//responsive timeline animation.
//values recorded once, nothing changes on resize
// var tl = new TimelineMax({repeat:-1, yoyo:true, repeatDelay:1})
var tl = new TimelineMax()
// make the timeline duration equal to the number of boxes (in seconds)
/* // Instead of animating a percentage, we animate the calculated
// width above , `_animateWidth`
*/
tl.to(".tlContent", _boxCount, {x:-(_animateWidth), force3D:true, ease: Power0.easeNone});
/* // I modified nothing below
*/
tl.pause();
// tl.play();
varctrl = $("#slider"),
ctrlValue = {value:0};
varctrl.slider({
animate: "fast",
range: false,
min: 0,
max: 100,
step:.1,
start:function() {
tl.pause();
},
slide: function ( event, ui ) {
tl.progress( ui.value / 100 );
console.log( ui.value/100 );
},
stop: function() {
var _curProgress = tl.progress();
var snapTo = closest( snapPoints , _curProgress );
TweenLite.to(tl, .5, {progress:snapTo, ease: Power3.easeOut});
$("#slider").slider( 'value' , snapTo*100 );
}
});
//tl.eventCallback("onUpdate", function() {
//trlValue.value = tl.progress() * 100;
//varctrl.slider(ctrlValue);
//});
/* // Function to pass in an integer and retrun the closest value from set
*/
/**
* Returns the closest number from a sorted array.
**/
function closest(arr, target) {
if (!(arr) || arr.length == 0)
return null;
if (arr.length == 1)
return i[0];
for (var i=1; i<arr.length; i++) {
// As soon as a number bigger than target is found, return the previous or current
// number depending on which has smaller difference to the target.
if (arr[i] > target) {
var p = arr[i-1];
var c = arr[i]
return Math.abs( p-target ) < Math.abs( c-target ) ? p : c;
}
}
// No number in array is bigger so return the last.
return arr[arr.length-1];
}
/*
$('#debug').append('<div id="debug-mask">Mask</div>');
$('#debug').append('<div id="debug-animated">Animated Width</div>');
$('#debug').append('<div id="debug-tile">Tile</div>');
$('#debug').append('<div id="debug-snapPoints">Snap Increment</div>');
$('#debug-mask').width(_tlContainerWidth);
$('#debug-animated').width(_animateWidth);
$('#debug-tile').width(_boxwidth);
$('#debug-snapPoints').width( (_boxwidth/_animateWidth)*_animateWidth );
*/
Also see: Tab Triggers