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.
<!--
Made with LUME.
http://lume.io
-->
<script src="https://unpkg.com/lume@0.3.0-alpha.27/dist/global.js"></script>
<!-- Lume works with any framework. Here's we'll try out Vue because
it works with plain HTML, not requiring any build tool. -->
<script src="https://unpkg.com/vue@2.7.14/dist/vue.js"></script>
<!-- Tween.js is for smoothly animating numbers. We'll animate our buttons up and down. -->
<script src="https://unpkg.com/tween.js@16.6.0/src/Tween.js"></script>
<!-- Pointer Events polyfill (needed in Safari < 13) -->
<script src="https://code.jquery.com/pep/0.4.3/pep.js"></script>
<script>
LUME.defineElements()
</script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
body,
html {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
touch-action: none;
background: black;
}
lume-element3d {
text-align: center;
}
button {
width: 100%;
height: 100%;
white-space: nowrap;
border-radius: 10px;
border: none;
background: #595c5e;
color: #ccc;
outline: none;
font-family: 'Poppins', sans-serif;
font-weight: bold;
font-size: 16px;
}
button:focus,
button:hover {
background: #617e9f;
}
</style>
<template vue>
<form style="display: contents" onsubmit="console.log('Native form submission!'); event.preventDefault()">
<div style="width: 100%; height: 100%;">
<!-- Lights and shadows are powered by WebGL, but written with HTML: -->
<lume-scene
webgl="true"
id="scene"
background-color="black"
background-opacity="0"
perspective="600"
shadowmap-type="pcfsoft"
NOTE="one of basic, pcf, pcfsoft"
touch-action="none"
@pointermove="onmove"
@pointerdown="ondown"
@pointerup="onup"
physically-correct-lights
>
<lume-ambient-light color="#ffffff" intensity="2"></lume-ambient-light>
<lume-plane
ref="plane"
id="background"
size-mode="literal literal"
size="300 300 0"
align-point="0.5 0.5"
mount-point="0.5 0.5"
has="phong-material"
color="white"
dithering
color="white"
comment="free texture from https://polyhaven.com/a/concrete_layers_02"
texture="https://assets.codepen.io/191583/cement_wall_diff_2k.jpg"
bump-map="https://assets.codepen.io/191583/cement_wall_disp_2k.jpg"
bump-scale="8"
shininess="75"
specular="#222"
>
<lume-element3d
id="button-container"
position="0 0 20"
size="520 38 0"
align-point="0.5 0.5 0"
mount-point="0.5 0.5 0"
>
<lume-mixed-plane
v-for="(item, i) in buttons"
ref="btn"
:key="i"
size-mode="literal proportional"
size="120 1 0"
:align-point="`${i*0.333} 0 0`"
:mount-point="`${i*0.333} 0 0`"
color="#444"
has="rounded-rectangle-geometry"
corner-radius="10"
thickness="1"
quadratic-corners="false"
roughness="0.48"
>
<!-- Native button elements! -->
<button>{{item}}</button>
</lume-mixed-plane>
</lume-element3d>
</lume-plane>
<lume-element3d id="lightContainer" size="0 0 0" position="0 0 300">
<lume-point-light
id="light"
color="white"
size="0 0 0"
position="-50 -50"
:intensity="1000 / Math.PI"
shadow-map-width="2048"
shadow-map-height="2048"
shadow-radius="10"
distance="800"
shadow-bias="-0.001"
>
<lume-mesh
id="bulb"
has="sphere-geometry basic-material"
size="10 10 10"
mount-point="0.5 0.5 0.5"
color="white"
receive-shadow="false"
cast-shadow="false"
style="pointer-events: none"
></lume-mesh>
</lume-point-light>
</lume-element3d>
</lume-scene>
</div>
</form>
</template>
<div id="buttonsRoot"></div>
<script type="module">
const {Motor, Events} = LUME
new Vue({
el: '#buttonsRoot',
template: document.querySelector('[vue]').innerHTML,
data: () => ({
buttons: ['🏖️ Have Fun', '😊 Smi)e', '🛠️ Create', '♥️ With Love'],
}),
mounted() {
const lightContainer = document.querySelector('#lightContainer')
const bulb = document.querySelector('#bulb')
const plane = this.$refs.plane
this.targetPosition = {x: window.innerWidth / 2, y: window.innerHeight / 2}
Motor.addRenderTask(time => {
lightContainer.position.x += (this.targetPosition.x - lightContainer.position.x) * 0.05
lightContainer.position.y += (this.targetPosition.y - lightContainer.position.y) * 0.05
plane.rotation.y = 10 * (lightContainer.position.x / window.innerWidth) - 5
plane.rotation.x = -(10 * (lightContainer.position.y / window.innerHeight) - 5)
})
window.addEventListener('resize', resize)
resize()
function resize() {
const winAspect = window.innerWidth / window.innerHeight
if (winAspect < 1) plane.size = [window.innerHeight * 1.3, window.innerHeight * 1.3]
else plane.size = [window.innerWidth * 1.3, window.innerWidth * 1.3]
}
},
methods: {
onmove(e) {
e.preventDefault()
this.targetPosition.x = e.clientX
this.targetPosition.y = e.clientY
},
// On mouse down animate the button downward using Tween.js
// https://github.com/tweenjs/tween.js
ondown(e) {
if (e.target.matches('button')) {
this.pressedButton = e.target
if (this.upTween) {
this.upTween.stop()
this.upTween = null
}
this.downTween = new TWEEN.Tween(e.target.parentNode.position)
.to({z: -16}, 75)
.start()
.onComplete(() => (this.downTween = null))
Motor.addRenderTask(time => {
if (!this.downTween) return false
this.downTween.update(time)
})
}
},
// On mouse up animate the button upward using Tween.js
onup() {
if (this.pressedButton) {
if (this.downTween) {
this.downTween.stop()
this.downTween = null
}
this.upTween = new TWEEN.Tween(this.pressedButton.parentNode.position)
.to({z: 0}, 75)
.start()
.onComplete(() => (this.upTween = null))
Motor.addRenderTask(time => {
if (!this.upTween) return false
this.upTween.update(time)
})
}
},
},
})
</script>
Also see: Tab Triggers