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.
<div id="content" class="contentino" onMouseOut="mouseOnContent(false)" onMouseOver="mouseOnContent(true)"><canvas id="canvas"></canvas></div>
html, body {
/*background: transparent !important;*/
background-color: rgb(0,0,255);
margin: 0;
border: 0;
width: 100%;
height: 100%;
overflow: hidden;
position: relative;
}
#canvas {
position: fixed;
background: transparent;
width: inherit;
height: inherit;
}
.contentino {
border-radius: 0px;
border: none;
background: rgba(0, 0, 0, 0);
position: absolute;
overflow: hidden;
display: block;
z-index: 4;
}
gsap.defaults({overwrite: "true"});
CustomEase.create("ew","M0,0,C0,0,0.114,0.85,0.134,0.932,0.178,1.16,0.242,1.028,0.246,1.01,0.264,0.958,0.253,1.009,0.28,0.876,0.312,0.716,0.356,0.834,0.37,0.882,0.384,0.931,0.379,0.965,0.41,1.006,0.46,1.088,0.484,1.022,0.53,0.997,0.58,0.964,0.667,1.002,0.725,1.004,0.829,1.008,1,1,1,1");
var multiplexer=16;
let maxAnimationLength = 1.5;
let elementAnimationTime = .75;
let x_elem= 0;
let y_elem= 0;
let canAnimate = false;
let doAnimate = true;
var extra_height=0;
////
var tiles=[];
var canvas = document.querySelector("#canvas");
var context = canvas.getContext("2d");
function render() {
context.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < tiles.length; i++) {
var tile = tiles[i];
tile.draw(context);
}
}
function setDimensions() {
intW = window.innerWidth-80;
intH = window.innerHeight+extra_height;
scaled_img_w = Math.ceil((intW)*0.9);
scaled_img_h = Math.floor((intH)*0.75);
img_x = Math.ceil(((intW/2)-(scaled_img_w/2)));
img_y = Math.ceil(((intH/2)-(scaled_img_h)/2))-14;
if (document.getElementById) {
var theIframe = document.getElementById("content");
if (theIframe) {
theIframe.style.width = Math.ceil((scaled_img_w+40)/10)*10+"px";
theIframe.style.height = Math.ceil((scaled_img_h)/10)*10+"px";
let ofx = Math.ceil((img_x+12)/10)*10;
theIframe.style.marginLeft = ofx+"px";
let ofy = Math.ceil((img_y-16)/10)*10;
theIframe.style.marginTop = ofy+"px";
canvas.width = gsap.getProperty("#content","width");
canvas.height = gsap.getProperty("#content","height");
}
}
}
window.onresize = function() {
tiles=[];
gsap.ticker.remove(render);
setDimensions();
drawSquares();
}
//initilize animation on enter
function loadContent(){
setDimensions();
////
x_elem= Math.ceil(gsap.getProperty("#content","width")/multiplexer);
y_elem= Math.ceil(gsap.getProperty("#content","height")/multiplexer)+1;
console.log("total:: ",x_elem,y_elem ,"("+(x_elem*y_elem)+")")
//perfOpt(x_elem*y_elem);
let rnd = Math.floor(gsap.utils.random(0,(x_elem*y_elem)));
for(let i_x=0;i_x<x_elem;i_x++){
for(let i_y=0;i_y<y_elem;i_y++){
var tile = createTile(((i_x*(multiplexer))+(multiplexer/4)), ((i_y*(multiplexer))+(multiplexer/4)), 0, 0, "rgba(255,255,255,1)");
tiles.push(tile);
}
}
gsap.to(tiles, {duration:maxAnimationLength,x:"-="+(multiplexer/4),y:"-="+(multiplexer/2),fill:"rgba(0,0,0,.4)",width:"+="+(multiplexer),height:"+="+(multiplexer),ease:"ew",stagger:{grid:[x_elem,y_elem],from:rnd,amount:elementAnimationTime},onComplete:swapBg});
gsap.ticker.add(render);
}
function createTile(x, y, width, height, fill) {
var tile = {
x: x,
y: y,
width: width,
height: height,
fill: fill,
draw: function(context) {
context.fillStyle = this.fill;
context.fillRect(this.x, this.y, this.width, this.height);
}
};
return tile;
}
//landing point after initial animation
function swapBg(){
document.addEventListener("click", printMousePos);
//$('#content').empty();
//gsap.to("#content",{duration:1,borderRadius: 18})
//gsap.set("#content",{background: "rgba(0, 0, 0, .4)"});
}
//onn window resize pdate
function drawSquares (){
x_elem= Math.ceil(gsap.getProperty("#content","width")/multiplexer);
y_elem= Math.ceil(gsap.getProperty("#content","height")/multiplexer)+1;
let rnd = Math.floor(gsap.utils.random(0,(x_elem*y_elem)));
for(let i_x=0;i_x<x_elem;i_x++){
for(let i_y=0;i_y<y_elem;i_y++){
var tile = createTile(i_x*(multiplexer), i_y*(multiplexer), multiplexer, multiplexer, "rgba(0,0,0,.4)");
tiles.push(tile);
}
}
gsap.ticker.add(render);
}
//on click events
function reanim(t,x_lim,y_lim){
if(doAnimate){
//calculation to get surrounding tiles from point of origin
let saveTiles = tiles;
let start_At_X = 0;
let end_At_X = 0;
let start_At_Y = 0;
let end_At_Y = 0;
let maxSurroundElems = 10;
//x validity
if((x_lim-maxSurroundElems)<0){
start_At_X = 0;
}else{
start_At_X = (x_lim-10);
}
///
if((x_lim+maxSurroundElems)>x_elem){
end_At_X = x_elem;
}else{
end_At_X = (x_lim+10);
}
//y validity
if((y_lim-maxSurroundElems)<0){
start_At_Y = 0;
}else{
start_At_Y = (y_lim-10);
}
///
if((y_lim+maxSurroundElems)>y_elem){
end_At_Y = y_elem;
}else{
end_At_Y = (y_lim+10);
}
console.log(start_At_X,end_At_X,start_At_Y,end_At_Y)
let xps = end_At_X-start_At_X;
let yps = end_At_Y-start_At_Y;
////
//here we get new arr of tiles that only should be animated
/*let op = [];
for(let xd=start_At_X;xd<end_At_X;xd++){
for(let yd=start_At_Y;yd<end_At_Y;yd++){
var tile = createTile(xd*(multiplexer), yd*(multiplexer), multiplexer, multiplexer, "rgba(0,0,0,.4)");
op.push(tile);
}
}*/
let ofseter = (multiplexer/2);
//grid:[x_elem,y_elem],
//let tyt= tiles.slice(0,10)
//console.log(tyt)
gsap.to(tiles, {x:"+="+(ofseter/2),y:"+="+(ofseter/2),width:"-="+(ofseter),height:"-="+(ofseter),duration:maxAnimationLength/4,ease:"Circ.in",stagger:{grid:[x_elem,y_elem],from:t,amount:elementAnimationTime/2},onStart:function(){doAnimate = false;}});
gsap.to(tiles, {x:"-="+(ofseter/2),y:"-="+(ofseter/2),width:"+="+(ofseter),height:"+="+(ofseter),duration:maxAnimationLength/2,ease:"ew",delay:(maxAnimationLength/4)+.1,stagger:{grid:[x_elem,y_elem],from:t,amount:elementAnimationTime},
onComplete:function(){
doAnimate=true;
}});
gsap.ticker.add(render);
}
}
function printMousePos(event) {
if(canAnimate){
let xc = Math.ceil(((event.clientX)-$('#content').offset().left)/multiplexer);
let yc = Math.ceil(((event.clientY)-$('#content').offset().top)/multiplexer);
reanim((((xc-1)*(y_elem-1))+(xc-1)+(yc-1)),(xc-1),(yc-1));
}
}
function mouseOnContent(s){
canAnimate = s;
}
loadContent();
Also see: Tab Triggers