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.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script defer src="main.js"></script>
<title>ELEVADOR</title>
<!-- HTML -->
<!-- Custom Styles -->
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- ELEVADOR -->
<section>
<div class="andar">5</div>
<div class="andar">4</div>
<div class="andar">3</div>
<div class="andar">2</div>
<div class="andar">T</div>
</section>
<div id="elevador" class="doorClosed" data-lastplace="1" data-door="false"> </div>
<!-- PAINEL -->
<aside>
<div id="display">05▼</div>
<nav id="navbtns">
<button class="btn" id="btn-5">5</button>
<button class="btn" id="btn-4">4</button>
<button class="btn" id="btn-3">3</button>
<button class="btn" id="btn-2">2</button>
<button class="btn" id="btn-T">T</button>
<button class="btn" id="btn-A">Abrir</button>
<button class="btn" id="btn-F">Fechar</button>
<button class="btn" disabled id="btn-E">Emerg.</button>
</nav>
<div id="display2">01▲</div>
<nav id="navbtns2">
<button class="btn" id="btn-Up">▲</button>
<button class="btn" id="btn-Down">▼</button>
</nav>
</aside>
</body>
</html>
* {
margin:0;
padding:0;
border-collapse: collapse;
/*border-style: groove;*/
}
@font-face{
font-family:bedstead;
src:url(http://bjh21.me.uk/bedstead/bedstead.otf);
font-weight:500;
font-style:normal;
}
body{
display: flex;
flex-direction: row;
width: 100vw;
height: 100vh;
flex-wrap: nowrap;
align-content: stretch;
justify-content: space-between;
align-items: flex-start;
}
section{
background-color: #555;
display: grid;
flex-direction: column;
width: 60vw;
height: 100vh;
}
.andar{
width:60vw;
height:19.5vh;
border:solid 1px red;
background-color: #6d6d6d;
grid-template-columns: 20vh 20vh;
}
#elevador{
display: flex;
align-items: center;
text-align: center;
justify-content: center;
width: 20vh;
height:19.8vh;
position: absolute;
left:calc(60vw - 20vh);
top:0vh;
background-color: #ccc;
color:#333;
border:solid 1vh transparent;
border-bottom:.2vh solid transparent!important;
border-top:.2vh solid transparent!important;
box-sizing: border-box;
z-index:5;
transition-property: color, border-width;
transition: border-width 0.6s linear,color 0.6s;
transition-delay:250ms;
}
.doorOpen {
border-left:2vh solid green!important;
border-right:2vh solid green!important;
}
.doorClosed {
border-left:10vh solid red!important;
border-right:10vh solid red!important;
color:transparent!important;
}
aside{
position: relative;
background-color: #AAA;
width:40vw;
height:100vh;
display:flex;
flex-direction: column;
flex-wrap: wrap;
align-content: center;
justify-content: space-around;
align-items: center;
}
#display,#display2{
width: 15vw;
margin: 0;
min-height:10vh;
background-color:#FFF;
display:flex;
justify-content: center;
justify-items: center;
align-content: center;
vertical-align: center;
align-items: center;
font-size:xx-large;
font-family:bedstead;
color:#0000ff;
text-shadow:0px 0px 3px #fff;
/*text-decoration:underline overline;
text-decoration-color: blue;*/
background-color:rgba(225,225,225,.9);
background-image: radial-gradient(#2f2f2f30, #ffffff30, #8f8f8f90);
border:solid 1px rgba(255,255,255,.5);
border-right-color:rgba(255,255,255,.2);
border-bottom-color:rgba(255,255,255,.2);
box-shadow:0 0px 9px rgba(0,0,0,.8);
backdrop-filter:blur(1.5px);
border-radius:5px;
padding:5vh 0;
line-height:8vh;
}
#navbtns{
display:grid;
grid-template-columns: 2fr 2fr;
justify-content: center;
align-content: stretch;
align-items: stretch;
justify-items: center;
margin:0 auto;
gap:0;
background-color:rgba(225,225,225,.2);
border:solid 1px rgba(255,255,255,.5);
border-right-color:rgba(255,255,255,.2);
border-bottom-color:rgba(255,255,255,.2);
box-shadow:0 0px 9px rgba(0,0,0,.8);
backdrop-filter:blur(1.5px);
border-radius:5px;
}
#navbtns>button{
width:10vh;
height:10vh;
/*align-self: center;*/
border:#222;
margin:2vh;
--paper-ripple-opacity: .3;
-webkit-tap-highlight-color: transparent;
align-items: center;
border: 1px solid gray;
border-radius: 100%;
box-sizing: border-box;
color: #2f2fff;
cursor: pointer;
display: inline-flex;
flex-shrink: 0;
font-size:x-large;
font-weight: 500;
box-shadow:0px 0px 8px #1569ff;
outline:solid 1px #1569ff;
justify-content: center;
overflow: hidden;
position: relative;
user-select: none;
}
#navbtns>button:not(button:disabled):hover{
box-shadow:0px 0px 12px #0589ff!important;
outline:solid 1px #0589ff!important;
color:#2f2fff!important;
}
button:nth-last-child(1),
button:nth-last-child(2),
button:nth-last-child(3){
color: #7fafff!important;
font-size:medium!important;
}
button:disabled{
box-shadow:0px 0px 8px #151515!important;
outline:solid 1px #000!important;
color:#9d2332!important;
cursor:default!important;
opacity:.7;
}
#navbtns2 {
display:grid;
grid-template-columns: 1fr;
justify-content: center;
align-content: stretch;
align-items: stretch;
justify-items: center;
margin:0 auto;
gap:0;
background-color:rgba(225,225,225,.2);
border:solid 1px rgba(255,255,255,.5);
border-right-color:rgba(255,255,255,.2);
border-bottom-color:rgba(255,255,255,.2);
box-shadow:0 0px 9px rgba(0,0,0,.8);
backdrop-filter:blur(1.5px);
border-radius:5px;
}
#navbtns2>button{
width:10vh;
height:fit-content;
/*align-self: center;*/
border:#222;
margin:2vh;
--paper-ripple-opacity: .5;
-webkit-tap-highlight-color: transparent;
align-items: center;
border: 1px solid gray;
border-radius: 3px;
box-sizing: border-box;
cursor: pointer;
display: inline-flex;
flex-shrink: 0;
font-weight: 500;
font-size:medium;
justify-content: center;
outline-width: 0;
overflow: hidden;
position: relative;
user-select: none;
}
const andar = document.querySelectorAll('.andar')
const elevador = document.querySelector('#elevador')
const display = document.querySelector('#display')
const navbtns = document.querySelector('#navbtns')
const btn = document.querySelectorAll('.btn')
const display2 = document.querySelector('#display2')
const btnUp = document.querySelector('#btn-Up')
const btnDown = document.querySelector('#btn-Down')
const andarOffSetT = andar[4].offsetTop
const andarOffSet2 = andar[3].offsetTop
const andarOffSet3 = andar[2].offsetTop
const andarOffSet4 = andar[1].offsetTop
const andarOffSet5 = andar[0].offsetTop
// ▲ ▼
var lastPlace
var timerDuration = 2000
var inMoving = false
var myInterval
var elDir = '▼'
var fechar = false
elevador.onanimationend = ()=>{
console.log(inMoving,elevador.dataset.door,'aaaa')
}
elevador.ontransitionstart = (event) => {
inMoving = true
elevador.dataset.door = 'true'
//Array.from(btn).forEach( elm => elm.classList.add('disabled'))
elevador.textContent = 'aguarde...'
};
elevador.ontransitionend = (event) => {
if(elevador.classList.contains('doorOpen'))return
inMoving = false
fechar = true
elevador.dataset.door = 'false'
elevador.innerHTML = ' '
Array.from(btn).forEach( elm => elm.removeAttribute('disabled'))
btn[(elevador.dataset.lastplace-5)*(-1)].setAttribute('disabled',null)
if(elevador.dataset.lastplace == '5')btnUp.setAttribute('disabled',null)
if(elevador.dataset.lastplace == '1')btnDown.setAttribute('disabled',null)
console.log(elevador.dataset.lastplace)
};
Array.from(btn).forEach(elm =>{
elm.addEventListener("click", e => {
if(lastPlace === undefined) lastPlace = andarOffSetT
if(e.target === navbtns.children[0]){
// IR PARA 5º
if(inMoving === true || elevador.dataset.door == 'true'){
return
} else {
if(lastPlace === undefined) lastPlace=andarOffSet5
if(lastPlace === andarOffSet4) timerDuration = 500
if(lastPlace === andarOffSet3) timerDuration = 1000
if(lastPlace === andarOffSet2) timerDuration = 1500
if(lastPlace === andarOffSetT) timerDuration = 2000
if(lastPlace === andarOffSet5) return
setTimeout(()=>{
elevChanges(andarOffSet5,5);lastPlace=andarOffSet5
},250)
}
}
if(e.target === navbtns.children[1]){
// IR PARA 4º
if(inMoving === true || elevador.dataset.door == 'true'){
return
} else {
if(lastPlace === undefined) lastPlace=andarOffSet4
if(lastPlace === andarOffSet5) timerDuration = 500
if(lastPlace === andarOffSet3) timerDuration = 500
if(lastPlace === andarOffSet2) timerDuration = 1000
if(lastPlace === andarOffSetT) timerDuration = 1500
if(lastPlace === andarOffSet4) return
setTimeout(()=>{elevChanges(andarOffSet4,4);lastPlace=andarOffSet4},250)
}
}
if(e.target === navbtns.children[2]){
// IR PARA 3º
if(inMoving === true || elevador.dataset.door == 'true'){
return
} else {
if(lastPlace === undefined) lastPlace=andarOffSet3
if(lastPlace === andarOffSet5) timerDuration = 1000
if(lastPlace === andarOffSet4) timerDuration = 500
if(lastPlace === andarOffSet2) timerDuration = 500
if(lastPlace === andarOffSetT) timerDuration = 1000
if(lastPlace === andarOffSet3) return
setTimeout(()=>{elevChanges(andarOffSet3,3);lastPlace=andarOffSet3},250)
}
}
if(e.target === navbtns.children[3]){
// IR PARA 2º
if(inMoving === true || elevador.dataset.door == 'true'){
return
} else {
if(lastPlace === undefined) lastPlace=andarOffSet2
if(lastPlace === andarOffSet5) timerDuration = 1500
if(lastPlace === andarOffSet4) timerDuration = 1000
if(lastPlace === andarOffSet3) timerDuration = 500
if(lastPlace === andarOffSetT) timerDuration = 500
if(lastPlace === andarOffSet2) return
setTimeout(()=>{elevChanges(andarOffSet2,2);lastPlace=andarOffSet2},250)
}
}
if(e.target === navbtns.children[4]){
//ir para T
if(inMoving === true || elevador.dataset.door == 'true'){
return
} else {
if(lastPlace === undefined) lastPlace=andarOffSetT
if(lastPlace === andarOffSet5) timerDuration = 2000
if(lastPlace === andarOffSet4) timerDuration = 1500
if(lastPlace === andarOffSet3) timerDuration = 1000
if(lastPlace === andarOffSet2) timerDuration = 500
if(lastPlace === andarOffSetT) return
setTimeout(()=>{elevChanges(andarOffSetT,1);lastPlace=andarOffSetT},250)
}
}
// BTN ABRIR PORTA
if(e.target === navbtns.children[5] &&
inMoving === false && elevador.classList.contains('doorClosed')) checkDoor()
// BTN FECHAR PORTA
if(e.target === navbtns.children[6] && fechar == true){
elevador.classList.add('doorClosed')
elevador.classList.remove('doorOpen')
fechar = false
}
// BTN EMERG
if(e.target === navbtns.children[7]){
alert('EMERGÊNCIA!')
console.log(e.target)
}
// BTN UP
if(e.target === navbtns.children[8]){
console.log('up')
}
//BTN DOWN
if(e.target === navbtns.children[9]){
console.log('down')
}
})
})
function checkDoor(){
if(inMoving === true && elevador.dataset.door == 'true') return
setTimeout(()=>{
elevador.classList.remove('doorClosed')
elevador.classList.add('doorOpen')
fechar = true
setTimeout(()=>{
elevador.classList.add('doorClosed')
elevador.classList.remove('doorOpen')
fechar = false
},4500)
},250)
}
let txt = display.textContent
function elevChanges(clicked,placeTarget){
Array.from(btn).forEach( elm => elm.setAttribute('disabled',null))
let curPlace = parseInt(elevador.dataset.lastplace)
if(curPlace>placeTarget){
elDir = '▼'
}else{
elDir = '▲'
}
elevador.dataset.lastplace = placeTarget
elevador.animate([{top: `${clicked}px`}],
{duration: timerDuration,iterations: 1,fill: "forwards"})
inMoving = true
Promise.all(elevador.getAnimations().
map((animation) => animation.finished)).then(() => {inMoving = false
clearInterval(myInterval)
display.textContent = `0${placeTarget}${elDir}`
if(display.textContent === `05▲`){
display.textContent = `05▼`;
display2.textContent = `05▼`;
}
if(display.textContent === `01▼`){
display.textContent = `01▲`;
display2.textContent = `01▲`;
}
elevador.dataset.door = 'true'
checkDoor()
})
myInterval = setInterval(()=>{displayChanges(curPlace,placeTarget)},250)
}
function displayChanges(c,p){
if(elevador.offsetTop <= andarOffSetT + 20) display.textContent = `01▲`
if(elevador.offsetTop <= andarOffSet2 + 20) display.textContent = `02${elDir}`
if(elevador.offsetTop <= andarOffSet3 + 20) display.textContent = `03${elDir}`
if(elevador.offsetTop <= andarOffSet4 + 20) display.textContent = `04${elDir}`
if(elevador.offsetTop <= andarOffSet5 + 20) display.textContent = `05▼`
display2.textContent = display.textContent
}
setTimeout(()=>{elevChanges(andarOffSetT,1)},250)
Also see: Tab Triggers