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.
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.
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.
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.
<template>
<section class="content-center gap-8 md:gap-9 grid grid-flow-row-dense items-center justify-center justify-items-center p-5">
<!-- Third Man Records -->
<img id="third-man-records" src="https://assets.codepen.io/141041/Third+Man+Records.svg" alt="Third Man Records" class="w-72 md:w-96" />
<div id="visual" class="h-56 md:h-72 relative w-56 md:w-72">
<!-- Three JS Globe -->
<canvas id="three"></canvas>
<!-- Bottom Left Note -->
<img src="https://assets.codepen.io/141041/Third+Man+Records+Note.png" class="absolute left-0" style="bottom:20%;height:15%;width:15%" />
<!-- Top Right Double Note -->
<img src="https://assets.codepen.io/141041/Third+Man+Records+Double+Note.png" class="absolute right-0" style="height:15%;top:10%;width:15%" />
<!-- Top Right Note -->
<img src="https://assets.codepen.io/141041/Third+Man+Records+Note.png" class="absolute right-0" style="right:-20%;top:0%;height:15%;width:15%" />
</div>
<!-- Record -->
<img id="record" src="https://assets.codepen.io/141041/Third+Man+Records+Record.svg" alt="Record" class="w-60 md:w-80" />
<!-- Locations -->
<img id="locations" src="https://assets.codepen.io/141041/Third+Man+Records+Locations.svg" alt="Detroit . Nashville . London" class="w-60 md:w-80" />
</section>
</template>
<script>
export default{
methods: {
loadTexture(url) {
return new Promise((resolve, revoke) => {
// Initialize texture loader
const textureLoader = new THREE.TextureLoader()
// Load texture
textureLoader.load(url, (texture) => {
// Resolve
resolve(texture)
}, undefined, (error) => {
// Revoke
revoke(error)
})
})
},
async initializeThree() {
// Base
// ----------
// Get size
let { height, width } = document.getElementById('three').parentElement.getBoundingClientRect()
// Initialize scene
const scene = new THREE.Scene()
// Initialize camera
const camera = new THREE.PerspectiveCamera(20, 1, 0.1, 1000)
// Position camera
camera.position.z = 5.6
// Initialize renderer
const renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true,
canvas: document.getElementById('three')
})
// Set renderer pixel ratio
renderer.setPixelRatio(window.devicePixelRatio)
// Set renderer size
renderer.setSize(width, height)
// World
// ----------
// Load world texture
const worldTexture = await this.loadTexture('https://assets.codepen.io/141041/Third-Man-Records-Equirectangular.png')
// Initialize world geometry
const worldGeometry = new THREE.SphereGeometry(1, 20, 20)
// Initialize world material
const worldMaterial = new THREE.MeshBasicMaterial({
color: 0xFFD200,
map: worldTexture
})
// Initialize world
const world = new THREE.Mesh(worldGeometry, worldMaterial)
// Rotate world
world.rotation.y = THREE.MathUtils.degToRad(-25)
// Pivot
// ----------
// Add pivot group
const pivotGroup = new THREE.Group()
// Rotate pivot group
pivotGroup.rotation.z = THREE.MathUtils.degToRad(10)
// Add world to pivot group
pivotGroup.add(world)
// Add pivot group to scene
scene.add(pivotGroup)
// Rendering
// ----------
// Loop
const render = () => {
// Request animation frame
requestAnimationFrame(render)
// Rotate world
world.rotation.y -= 0.005
// Render scene
renderer.render(scene, camera)
}
// Render
render()
// Resizing
// ----------
// Listen for window resizing
window.addEventListener('resize', () => {
// Get size
let { height, width } = document.getElementById('three').parentElement.getBoundingClientRect()
// Resize renderer
renderer.setSize(width, height)
})
}
},
mounted() {
// Initialize Three
this.initializeThree()
// Tween notes with Greensock
gsap.to(document.getElementById('visual').getElementsByTagName('img'), {
duration: 2,
ease: "power1.inOut",
repeat: -1,
repeatRefresh: true,
y: "random(20%, 40%)",
yoyo: true
})
}
}
</script>
<style>
html, body, section{
height: 100%;
width: 100%;
}
body{
background: #FFD200;
}
canvas{
border: 2px solid black;
border-radius: 100%;
}
@media (min-width: 1024px) {
section{
gap: 5vh !important;
}
img#third-man-records{
width: 60vh;
}
#visual{
height: 40vh;
width: 40vh;
}
img#record{
width: 50vh;
}
img#locations{
width: 50vh;
}
}
</style>
Also see: Tab Triggers