div.switch-button
span.active
button.switch-button-case.left.active-case Pizza
button.switch-button-case.right Pasta
a(class='signature', href='http://vanderlanth.io' target='_blank') Made with ♥ by vanderlanth
View Compiled
* {
margin: 0;
padding: 0;
}
html, body {
height: 100vh;
width: 100vw;
background-color: #151515;
}
.switch-button{
width: 400px;
height: 40px;
text-align: center;
position: absolute;
left: 50%;
top: 50%;
transform: translate3D(-50%, -50%, 0);
will-change: transform;
z-index: 197 !important;
cursor: pointer;
transition: .3s ease all;
border: 1px solid white;
&-case{
display: inline-block;
background: none;
width: 49%;
height: 100%;
color: white;
position: relative;
border: none;
transition: .3s ease all;
text-transform: uppercase;
letter-spacing: 5px;
padding-bottom: 1px;
&:hover{
color: grey;
cursor: pointer;
}
&:focus {
outline: none;
}
}
.active {
color: #151515;
background-color: white;
position: absolute;
left: 0;
top: 0;
width: 50%;
height: 100%;
z-index: -1;
transition: .3s ease-out all;
&-case{
color: #151515;
}
}
}
.signature {
position: fixed;
font-family: sans-serif;
font-weight: 100;
bottom: 10px;
left: 0;
letter-spacing: 4px;
font-size: 10px;
width: 100vw;
text-align: center;
color: white;
text-transform: uppercase;
text-decoration: none;
}
View Compiled
'use strict';
var switchButton = document.querySelector('.switch-button');
var switchBtnRight = document.querySelector('.switch-button-case.right');
var switchBtnLeft = document.querySelector('.switch-button-case.left');
var activeSwitch = document.querySelector('.active');
function switchLeft(){
switchBtnRight.classList.remove('active-case');
switchBtnLeft.classList.add('active-case');
activeSwitch.style.left = '0%';
}
function switchRight(){
switchBtnRight.classList.add('active-case');
switchBtnLeft.classList.remove('active-case');
activeSwitch.style.left = '50%';
}
switchBtnLeft.addEventListener('click', function(){
switchLeft();
}, false);
switchBtnRight.addEventListener('click', function(){
switchRight();
}, false);
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.