Pure CSS Image Comparison Slider

Category: CSS & CSS3 , Slider | August 17, 2015
Author:jcoulterdesign
Views Total:2,606 views
Official Page:Go to website
Last Update:August 17, 2015
License:MIT

Preview:

Pure CSS Image Comparison Slider

Description:

A pure HTM/CSS image comparison slider made using range slider input and  CSS :after and :before pseudo classes for the slider thumb.

Currently works on webkit based browsers: Chrome, Safari and Opera.

How to use it:

Create a range slider input for the image comparison slider.

<input type='range' value='50'>

Style the image comparison slider and add before / after images like so:

input[type='range'] {
  -webkit-appearance: none;
  -moz-appearance: none;
  background: none;
  display: block;
  cursor: pointer;
  margin: 0 auto;
  height: 10px;
  width: 444px;
  left: -10px;
  position: relative;
}
input[type='range']:after {
  content: '';
  width: 900px;
  position: absolute;
  height: 100vh;
  left: 31px;
  top: -8px;
  background-image: url(after.png);
  display: block;
  background-position: left;
  background-size: 400px;
  background-repeat: no-repeat;
}
input[type='range']:focus { outline: none; }
input[type='range']::-webkit-slider-thumb {
 -webkit-appearance: none;
 height: 30px;
 width: 15px;
 border-radius: 3px;
 background: #b378ef;
 cursor: pointer;
 margin-top: -14px;
 z-index: 99;
}
input[type='range']::-webkit-slider-thumb:before {
 content: '';
 width: 420px;
 border-left: 1px solid rgba(0, 0, 0, 0.12);
 position: relative;
 height: 100vh;
 top: 30px;
 left: 7px;
 z-index: 1;
 background-image: url(before.png);
 display: block;
 background-position: center center;
 background-size: 400px;
 background-repeat: no-repeat;
 background-attachment: fixed;
}

 

You Might Be Interested In:


Leave a Reply