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.
<div id="viewport">
<div id="content">
<canvas class="webgl"></canvas>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r124/three.min.js"></script>
<script src="https://unpkg.com/three@0.85.0/examples/js/controls/OrbitControls.js"></script>
@import url('https://fonts.googleapis.com/css?family=Signika+Negative:300,400&display=swap');
body {
background-color: #111;
font-family: "Signika Negative", sans-serif, Arial;
}
#viewport {
overflow: hidden;
position: fixed;
height: 100%;
width: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
#content {
overflow: visible;
width: 100%;
/* set a height because the contents are position: absolute, thus natively there's no height */
height: 2400px;
background-image:
linear-gradient(rgba(255,255,255,.07) 2px, transparent 2px),
linear-gradient(90deg, rgba(255,255,255,.07) 2px, transparent 2px),
linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
}
.box {
width: 100px;
height: 100px;
background-color: #28a92b;
position: absolute;
left: 300px;
z-index: 100;
line-height: 100px;
font-size: 50px;
text-align: center;
}
.box.active {
background-color: red;
}
.box-a {
top: 200px;
background-color: #8d3dae;
}
.box-b {
top: 600px;
}
.box-c {
top: 1000px;
background-color: #e26c16;
}
.line {
visibility: hidden;
width: 2px;
height: 3000px;
position: absolute;
left: 400px;
top: 0px;
background-color: #777;
}
header .name {
color: white;
}
.title {
position: absolute;
width: 100%;
text-align: center;
color: white;
font-weight: 400;
font-size: 40px;
}
header {
position: fixed;
right: 0px;
bottom: 0px;
padding: 6px 10px 10px 12px;
border-top-left-radius: 26px;
z-index: 100;
background-color: rgba(0,0,0,0.5);
}
// Canvas
const canvas = document.querySelector('canvas.webgl')
// Scene
const scene = new THREE.Scene()
const renderer = new THREE.WebGLRenderer({
canvas: canvas,
alpha: true
})
smoothScroll("#content");
/**
* Lights
*/
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8)
scene.add(ambientLight)
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.6)
directionalLight.position.set(5, 5, 5)
scene.add(directionalLight)
/**
* Sizes
*/
const sizes = {
width: window.innerWidth,
height: window.innerHeight
}
const geometry = new THREE.SphereGeometry(8, 21, 21);
const sphereMaterial = new THREE.MeshBasicMaterial({ color: 'red' });
const sphere = new THREE.Mesh(geometry, sphereMaterial);
scene.add(sphere)
sphere.position.y = 1
window.addEventListener('resize', () => {
// Update sizes
sizes.width = window.innerWidth
sizes.height = window.innerHeight
// Update camera
camera.aspect = sizes.width / sizes.height
camera.updateProjectionMatrix()
// Update renderer
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
})
/**
* Camera
*/
// Base camera
const camera = new THREE.PerspectiveCamera(95, sizes.width / sizes.height, 0.1, 100)
camera.position.set(- 8, 4, 8)
scene.add(camera)
// Controls
const controls = new THREE.OrbitControls(camera, canvas)
controls.target.set(0, 1, 0)
controls.enableDamping = true
/**
* Renderer
*/
renderer.shadowMap.enabled = true
renderer.shadowMap.type = THREE.PCFSoftShadowMap
renderer.setSize(sizes.width, sizes.height)
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2))
/**
* Animate
*/
const clock = new THREE.Clock()
let previousTime = 0
const tick = () => {
const elapsedTime = clock.getElapsedTime()
const deltaTime = elapsedTime - previousTime
previousTime = elapsedTime
// Update controls
controls.update()
// Render
renderer.render(scene, camera)
// Call tick again on the next frame
window.requestAnimationFrame(tick)
}
tick()
//gsap
gsap.registerPlugin(ScrollTrigger);
//set camera position
camera.position.y = 1.5;
camera.position.z = -25;
camera.position.x = 1;
gsap.to(camera.position, {
x: 60,
z: -20,
y: 10,
ease: "Power2.easeInOut",
three: { scaleX: 2, scaleY: 1.5, x: 200, y: 100, opacity: 0.5 },
scrollTrigger:
{
trigger: renderer.domElement,
start: 'top top',
end: '+=500%',
pin: true,
scrub: true
},
onUpdate: function () {
//camera.lookAt(scene.position);
},
})
function smoothScroll(content, viewport, smoothness) {
content = gsap.utils.toArray(content)[0];
smoothness = smoothness || 9;
gsap.set(viewport || content.parentNode, {
overflow: "hidden",
position: "fixed",
height: "100%",
width: "100%",
top: 0,
left: 0,
right: 0,
bottom: 0
});
gsap.set(content, { overflow: "visible", width: "100%" });
let getProp = gsap.getProperty(content),
setProp = gsap.quickSetter(content, "y", "px"),
setScroll = ScrollTrigger.getScrollFunc(window),
removeScroll = () => (content.style.overflow = "visible"),
killScrub = (trigger) => {
let scrub = trigger.getTween
? trigger.getTween()
: gsap.getTweensOf(trigger.animation)[0]; // getTween() was added in 3.6.2
scrub && scrub.kill();
trigger.animation.progress(trigger.progress);
},
height,
isProxyScrolling;
function onResize() {
height = content.clientHeight;
content.style.overflow = "visible";
document.body.style.height = height + "px";
}
onResize();
ScrollTrigger.addEventListener("refreshInit", onResize);
ScrollTrigger.addEventListener("refresh", () => {
removeScroll();
requestAnimationFrame(removeScroll);
});
ScrollTrigger.defaults({ scroller: content });
ScrollTrigger.prototype.update = (p) => p; // works around an issue in ScrollTrigger 3.6.1 and earlier (fixed in 3.6.2, so this line could be deleted if you're using 3.6.2 or later)
ScrollTrigger.scrollerProxy(content, {
scrollTop(value) {
if (arguments.length) {
isProxyScrolling = true; // otherwise, if snapping was applied (or anything that attempted to SET the scroll proxy's scroll position), we'd set the scroll here which would then (on the next tick) update the content tween/ScrollTrigger which would try to smoothly animate to that new value, thus the scrub tween would impede the progress. So we use this flag to respond accordingly in the ScrollTrigger's onUpdate and effectively force the scrub to its end immediately.
setProp(-value);
setScroll(value);
return;
}
return -getProp("y");
},
getBoundingClientRect() {
return {
top: 0,
left: 0,
width: window.innerWidth,
height: window.innerHeight
};
}
});
return ScrollTrigger.create({
animation: gsap.fromTo(
content,
{ y: 0 },
{
y: () => document.documentElement.clientHeight - height,
ease: "none",
onUpdate: ScrollTrigger.update
}
),
scroller: window,
invalidateOnRefresh: true,
start: 0,
end: () => height - document.documentElement.clientHeight,
scrub: smoothness,
onUpdate: (self) => {
if (isProxyScrolling) {
killScrub(self);
isProxyScrolling = false;
}
},
onRefresh: killScrub // when the screen resizes, we just want the animation to immediately go to the appropriate spot rather than animating there, so basically kill the scrub.
});
}
Also see: Tab Triggers