checkbox-img-slider

In this example below you will see how to do a checkbox-img-slider with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by 1zm0, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright 1zm0 ©
  • HTML
  • CSS
  • JavaScript
    <ul class="slider">
  <li>
    <input type="radio" id="slide1" name="slide" checked> <label for="slide1"></label>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1689631/love-unite.jpg'></li>
  
  <li>
    <input type="radio" id="slide2" name="slide"> 
    <label for="slide2"></label>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1689631/sunshine.jpg'></li>
  
  <li>
    <input type="radio" id="slide3" name="slide"> 
    <label for="slide3"></label>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1689631/ta-smoke.jpg'></li>
  
  <li>
    <input type="radio" id="slide4" name="slide"> 
    <label for="slide4"></label>
    <img src='https://s3-us-west-2.amazonaws.com/s.cdpn.io/1689631/trees-tifo.jpg'></li>
  
  <div class="left-trigger">
     <div class="left-top"></div>
     <div class="left-bottom"></div>
  </div>
  <div class="right-trigger">
     <div class="right-top"></div>
     <div class="right-bottom"></div>
  </div>  
</ul>

/*Downloaded from https://www.codeseek.co/1zm0/checkbox-img-slider-Jvbavr */
    body {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction:column;
  position: fixed;
  top: 0;
  left: 0;
  background-color: skyblue;
}
.slider {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  height: 15em;
  width: 25em;
}

.slider li { 
  list-style: none; 
  position: absolute; 
}

.slider img { 
  height: 15em; 
  width: 25em; 
  vertical-align: top; 
}

.slider input { 
  display: none;
}

.slider label { 
  background-color: #fff; 
  bottom: 5px; 
  cursor: pointer; 
  display: block; 
  height: 10px; 
  position: absolute; 
  width: 10px; 
  z-index: 10;
  border-radius: 50%;
}

.slider li:nth-child(1) label { 
  left: 9.5em; 
} 
.slider li:nth-child(2) label { 
  left: 11em; 
} 
.slider li:nth-child(3) label { 
  left: 12.5em; 
} 
.slider li:nth-child(4) label { 
  left: 14em; 
} 
.slider img { 
  opacity: 0; 
  visibility: hidden; 
} 
.slider li input:checked ~ img { 
  opacity: 1; 
  visibility: visible; 
  z-index: 10; 
}

.slider li input:checked ~ label{
  background-color: black;
  border: solid 2px white;
  transition: .15s ease;
}
.left-trigger {
 width: 50px;
 height: 50px;
  background-color: green;
  border-radius: 5px;
  z-index: 12;
}

.right-trigger {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  width: 25px;
  height: 40px;
  background-color: green;
  z-index: 12;
  border-radius: 5px;
}
.right-trigger:hover {
  cursor: pointer;
}
.right-top {
  height: 5px;
  background-color: black;
  border-radius: 5px;
  transform: rotate(45deg);
}

.right-bottom {
  height: 5px;
  background-color: black;
  border-radius: 5px;
  transform: rotate(-45deg);
}

.left-trigger {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  width: 25px;
  height: 40px;
  background-color: green;
  border-radius: 5px;
}
.left-trigger:hover {
  cursor: pointer;
}
.left-top {
  height: 5px;
  background-color: black;
  border-radius: 5px;
  transform: rotate(-45deg);
}

.left-bottom {
  height: 5px;
  background-color: black;
  border-radius: 5px;
  transform: rotate(45deg);
}


/*Downloaded from https://www.codeseek.co/1zm0/checkbox-img-slider-Jvbavr */
    

Comments