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="wrap-texture">
<div id="canvas"></div>
<div class="planes">
<div class="draggable-container">
<div class="slider-names-container">
<div class="slider-names">
<div class="slider__name">Banorte</div>
<div class="slider__name">Event Planner</div>
<div class="slider__name">Honda</div>
<div class="slider__name">Banorte</div>
<div class="slider__name">Event Planner</div>
<div class="slider__name">Honda</div>
<div class="slider__name">Banorte</div>
<div class="slider__name">Event Planner</div>
</div>
</div>
<div class="draggable-hidden">
</div>
<div class="draggable-visible">
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/hKHqLpL/img-home-banorte.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/SmJ1bHb/img-home-event-planner.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/h19CF7C/img-home-honda.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/hKHqLpL/img-home-banorte.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/SmJ1bHb/img-home-event-planner.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/h19CF7C/img-home-honda.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/hKHqLpL/img-home-banorte.jpg" crossorigin="anonymous" /></div>
<div class="plane"><img data-sampler="planeTexture" class="texture" src="https://i.ibb.co/SmJ1bHb/img-home-event-planner.jpg" crossorigin="anonymous" /></div>
</div>
</div>
</div>
</div>
@font-face {
font-family: DomaineDisp;
font-weight: normal;
src: url(https://cdn.statically.io/gh/AlainBarrios/Fonts/b41a05199c312e4fada6cf977d40d76f2534e306/DomaineDisp-Regular.otf?raw=true);
}
*,
*::before,
*::after {
box-sizing: border-box;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
font-kerning: auto;
-webkit-text-size-adjust: 100%;
}
body {
/* make the body fits our viewport */
position: relative;
width: 100%;
height: 100vh;
margin: 0;
background-color: rgba(0, 0, 0, 1);
}
ul {
margin: 0;
padding: 0;
list-style: none;
}
img {
max-width: 100%;
display: block;
}
#wrap-texture {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100vh;
display: flex;
align-items: center;
}
#canvas {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
#canvas:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
}
.planes {
display: flex;
align-items: center;
width: 100%;
height: 100vh;
user-select: none;
position: relative;
cursor: grab;
white-space: nowrap;
overflow: hidden;
}
.draggable-container {
position: absolute;
height: 100%;
}
.slider-names-container {
--size: calc(7vmin + 1rem);
text-align: center;
font-family: DomaineDisp;
font-size: var(--size);
text-transform: uppercase;
pointer-events: none;
color: rgb(255, 255, 255);
overflow-y: hidden;
width: 100vw;
position: absolute;
top: 50%;
transform: translatey(-50%);
}
.draggable-visible {
display: grid;
grid-template-columns: repeat(8, minmax(480px, 1fr));
height: 100%;
grid-column-gap: 100px;
}
.draggable-hidden {
z-index: 5;
width: 100%;
height: 100%;
position: absolute;
}
.draggable-hidden .item {
height: 100%;
}
.grabbing {
cursor: grabbing;
}
.plane {
height: 100%;
}
.plane img {
display: none;
object-fit: cover;
width: 100%;
height: 100%;
}
console.clear();
const webGLCurtain = new Curtains({ container: "canvas" });
const planeContainer = document.querySelector(".planes");
const planeElements = planeContainer.querySelectorAll(".plane");
const draggableHidden = planeContainer.querySelector(".draggable-hidden");
const draggableVisible = planeContainer.querySelector(".draggable-visible");
const sliderNamesContainer = planeContainer.querySelector(
".slider-names-container"
);
const sliderNames = planeContainer.querySelector(".slider-names");
const names = planeContainer.querySelectorAll(".slider__name");
const items = planeContainer.querySelectorAll(".plane");
const draggie = new Draggabilly(draggableHidden, { axis: "x" });
sliderNamesContainer.style.height =
names[0].getBoundingClientRect().height + "px";
const width = innerWidth;
let mouse = {
currentPosX: 0,
previousPosX: 0,
minPosX: 0,
maxPosX: width - draggableHidden.getBoundingClientRect().width,
isMouseDown: false
};
let sliderNamesProps = {
containerHeight:
sliderNamesContainer.getBoundingClientRect().height -
sliderNames.getBoundingClientRect().height
};
let start = performance.now();
let velocity = 0;
let lastVelocity = 0;
let posNames = 0;
let lastPosNames = 0;
let amplitude = 0.1;
let lastMouse = 0;
let easing = 0.05;
let cancelAnimation = true;
let isOut = false;
const planes = [];
const MathUtils = {
lerp: (a, b, n) => (1 - n) * a + n * b,
map_range: (value, low1, high1, low2, high2) => {
return low2 + ((high2 - low2) * (value - low1)) / (high1 - low1);
}
};
const createCanvas = () => {
const shader = {
vertex: `
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265359
// those are the mandatory attributes that the lib sets
attribute vec3 aVertexPosition;
attribute vec2 aTextureCoord;
// those are mandatory uniforms that the lib sets and that contain our model view and projection matrix
uniform mat4 uMVMatrix;
uniform mat4 uPMatrix;
uniform mat4 planeTextureMatrix;
// if you want to pass your vertex and texture coords to the fragment shader
varying vec3 vVertexPosition;
varying vec2 vTextureCoord;
varying float vDirection;
uniform float uDirection;
void main() {
vec3 position = aVertexPosition;
float x = sin((position.y * 0.5 - 0.5) * PI) * uDirection;
position.x -= x;
gl_Position = uPMatrix * uMVMatrix * vec4(position, 1.0);
// set the varyings
vTextureCoord = (planeTextureMatrix * vec4(aTextureCoord, 0., 1.)).xy;
vVertexPosition = position;
vDirection = uDirection;
}`,
fragment: `
#ifdef GL_ES
precision mediump float;
#endif
#define PI2 6.28318530718
#define PI 3.14159265359
#define S(a,b,n) smoothstep(a,b,n)
// get our varyings
varying vec3 vVertexPosition;
varying vec2 vTextureCoord;
// the uniform we declared inside our javascript
uniform float uTime;
// our texture sampler (default name, to use a different name please refer to the documentation)
uniform sampler2D planeTexture;
varying float vDirection;
void main(){
vec2 uv = vTextureCoord;
float scale = -abs(vDirection) * 0.8;
uv = (uv - 0.5) * scale + uv;
float r = texture2D(planeTexture, vec2(uv.x - vDirection * 0.1, uv.y)).r;
float g = texture2D(planeTexture, vec2(uv.x - vDirection * 0.4, uv.y)).g;
float b = texture2D(planeTexture, vec2(uv.x - vDirection * 0.4, uv.y)).b;
gl_FragColor = vec4(r, g, b, 1.0);
}
`
};
const params = {
vertexShader: shader.vertex, // our vertex shader ID
fragmentShader: shader.fragment, // our framgent shader ID
widthSegments: 40,
heightSegments: 40, // we now have 40*40*6 = 9600 vertices !
uniforms: {
time: {
name: "uTime",
type: "1f",
value: 0
},
direction: {
name: "uDirection",
type: "1f",
value: 0
}
}
};
webGLCurtain.disableDrawing();
// crear nuestros planos
for (let i = 0; i < planeElements.length; i++) {
const plane = webGLCurtain.addPlane(planeElements[i], params);
planes.push(plane);
startPlane(items[i], plane);
}
initEvents();
requestAnimationFrame(onUpdate);
};
const startPlane = (planeElement, plane) => {
plane.onLoading(() => {
plane.mouseOver = false;
planeElement.addEventListener("mouseenter", () => {
plane.mouseOver = true;
webGLCurtain.enableDrawing();
});
planeElement.addEventListener("mouseleave", () => {
plane.mouseOver = false;
});
webGLCurtain.needRender();
});
};
const onUpdate = () => {
if (!cancelAnimation) {
for (let i = 0, l = planes.length; i < l; i++) {
planes[i].uniforms.direction.value = lastVelocity;
planes[i].updatePosition();
}
const { lerp } = MathUtils;
const now = performance.now();
const velocity =
((mouse.currentPosX - lastMouse) / (now - start)) * amplitude;
lastVelocity = lerp(lastVelocity, velocity, easing);
start = now;
lastMouse = mouse.currentPosX;
mouse.previousPosX = lerp(mouse.previousPosX, mouse.currentPosX, easing);
draggableVisible.style.transform = `translate3d(${mouse.previousPosX}px, 0, 0)`;
posNames =
(draggie.position.x / mouse.maxPosX) * sliderNamesProps.containerHeight;
lastPosNames = lerp(lastPosNames, posNames, easing);
sliderNames.style.transform = `translate3d(0,${lastPosNames}px,0)`;
if (Math.round(mouse.previousPosX) === mouse.currentPosX) {
webGLCurtain.disableDrawing();
cancelAnimation = true;
}
}
requestAnimationFrame(onUpdate);
};
// elemento arrastrar
const onDragMove = () => {
cancelAnimation = false;
webGLCurtain.enableDrawing();
// Si esta en el limite se trasladara la mitad del ancho del viewport
if (draggie.position.x > mouse.minPosX) {
mouse.currentPosX = MathUtils.map_range(
draggie.position.x,
0,
innerWidth,
0,
innerWidth / 3
);
} else if (draggie.position.x < mouse.maxPosX) {
mouse.currentPosX = MathUtils.map_range(
draggie.position.x,
mouse.maxPosX,
mouse.maxPosX - innerWidth,
mouse.maxPosX,
mouse.maxPosX - innerWidth / 3
);
} else {
mouse.currentPosX = draggie.position.x;
easing = 0.05;
}
amplitude = 0.1;
};
const onDragStart = (e) => {
planeContainer.style.cursor = "grabbing"; // Aplica al cursor el icono de agarrando;
};
const onDragEnd = () => {
planeContainer.style.cursor = "grab"; // Aplica al cursor el icono de agarrar
// Si esta en el limite volvera a su posicion inicial o final
if (draggie.position.x > mouse.minPosX) {
mouse.currentPosX = 0;
draggie.setPosition(mouse.currentPosX, draggie.position.y);
amplitude = 0;
easing = 0.07;
} else if (draggie.position.x < mouse.maxPosX) {
mouse.currentPosX = mouse.maxPosX;
draggie.setPosition(mouse.currentPosX, draggie.position.y);
amplitude = 0;
easing = 0.07;
} else {
draggie.setPosition(mouse.currentPosX, draggie.position.y);
}
};
// Al reescalar calcula denuevo la posicion maxima
const onResize = () => {
sliderNamesContainer.style.height =
names[0].getBoundingClientRect().height + "px";
mouse.maxPosX =
window.innerWidth - draggableHidden.getBoundingClientRect().width;
sliderNamesProps = {
containerHeight:
sliderNamesContainer.getBoundingClientRect().height -
sliderNames.getBoundingClientRect().height
};
};
const initEvents = () => {
draggie.on("dragMove", () => {
if (isOut) return;
onDragMove();
});
draggie.on("pointerDown", () => {
isOut = false;
onDragStart();
});
draggie.on("pointerUp", onDragEnd);
planeContainer.addEventListener("mouseleave", () => {
isOut = true;
onDragEnd();
});
window.addEventListener("resize", onResize);
};
window.addEventListener("load", createCanvas);
Also see: Tab Triggers