Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

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.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource

Packages

Add Packages

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.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <!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">&nbsp;</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>

              
            
!

CSS

              
                * {
    
    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;
}

              
            
!

JS

              
                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 = '&nbsp;'
		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)

              
            
!
999px

Console