JSFiddle - React, Tailwind, and code Playground
by godsnake
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.j"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
<div style="" class="container pb-2" id="signupForm">
<div style="" class="container pb-2" id="signupForm">
<div class="toggler pointer" id="filt-monthly">Monthly </div>
<label class="toggle">
<input type="checkbox" id="switcher" class="check"/>
<b class="b switch"></b>
</label>
<div class="toggler pointer" id="filt-annual"> Annual</div>
</div>
<div id="annually" class=" wrapper-full">
<div class="container bg-primary">
<p class="text-white">
Hello This is priced annually
</p>
</div>
</div>
<div id="monthly" class="hide wrapper-full">
<div class="container bg-secondary">
<p class="text-white">
Hello This is priced monthly
</p>
</div>
</div>
CSS
.toggler {
display: inline-block;
vertical-align: middle;
margin: 12px 0 0 0;
color: #ddd;
transition: .2s;
font-weight: bold;
}
.toggler--is-active {
color: #000000;
}
.b {
display: block;
}
.hide{
display: none;
}
/* slide/switch */
.toggle {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}
.toggle input {
opacity: 0;
width: 0;
height: 0;
}
.switch {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
cursor: pointer;
background-color: #999;
-webkit-transition: .4s;
transition: .4s;
border-radius: 34px;
}
.switch:before {
position: absolute;
bottom: 4px; left: 4px;
content: "";
width: 26px;
height: 26px;
background-color: #fff;
-webkit-transition: .4s;
transition: .4s;
border-radius: 50%;
}
input:checked + .switch {
background-color: #f66;
}
input:focus + .switch {
box-shadow: 0 0 1px #f66;
}
input:checked + .switch:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}
JavaScript
var e = document.getElementById("filt-monthly"),
d = document.getElementById("filt-annual"),
t = document.getElementById("switcher"),
m = document.getElementById("monthly"),
y = document.getElementById("annually");
e.addEventListener("click", function(){
t.checked = false;
e.classList.add("toggler--is-active");
d.classList.remove("toggler--is-active");
m.classList.remove("hide");
y.classList.add("hide");
});
d.addEventListener("click", function(){
t.checked = true;
d.classList.add("toggler--is-active");
e.classList.remove("toggler--is-active");
m.classList.add("hide");
y.classList.remove("hide");
});
t.addEventListener("click", function(){
d.classList.toggle("toggler--is-active");
e.classList.toggle("toggler--is-active");
m.classList.toggle("hide");
y.classList.toggle("hide");
})