_comparison-sliders.scss 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Image comparison slider
  2. // Credit: http://codepen.io/solipsistacp/pen/Gpmaq
  3. .comparison-slider {
  4. height: 50vh;
  5. overflow: hidden;
  6. position: relative;
  7. width: 100%;
  8. -webkit-overflow-scrolling: touch;
  9. .comparison-before,
  10. .comparison-after {
  11. height: 100%;
  12. left: 0;
  13. margin: 0;
  14. overflow: hidden;
  15. position: absolute;
  16. top: 0;
  17. img {
  18. height: 100%;
  19. object-fit: cover;
  20. object-position: left center;
  21. position: absolute;
  22. width: 100%;
  23. }
  24. }
  25. .comparison-before {
  26. width: 100%;
  27. z-index: 1;
  28. .comparison-label {
  29. right: $unit-4;
  30. }
  31. }
  32. .comparison-after {
  33. max-width: 100%;
  34. min-width: 0;
  35. z-index: 2;
  36. &::before {
  37. background: transparent;
  38. content: "";
  39. cursor: default;
  40. height: 100%;
  41. left: 0;
  42. position: absolute;
  43. right: $unit-4;
  44. top: 0;
  45. z-index: $zindex-0;
  46. }
  47. &::after {
  48. background: currentColor;
  49. border-radius: 50%;
  50. box-shadow: 0 -5px, 0 5px;
  51. color: $light-color;
  52. content: "";
  53. height: 3px;
  54. position: absolute;
  55. right: $unit-2;
  56. top: 50%;
  57. transform: translate(50%, -50%);
  58. width: 3px;
  59. }
  60. .comparison-label {
  61. left: $unit-4;
  62. }
  63. }
  64. .comparison-resizer {
  65. animation: first-run 1.5s 1 ease-in-out;
  66. cursor: ew-resize;
  67. height: $unit-4;
  68. left: 0;
  69. max-width: 100%;
  70. min-width: $unit-4;
  71. opacity: 0;
  72. outline: none;
  73. position: relative;
  74. resize: horizontal;
  75. top: 50%;
  76. transform: translateY(-50%) scaleY(30);
  77. width: 0;
  78. }
  79. .comparison-label {
  80. background: rgba($dark-color, .5);
  81. bottom: $unit-4;
  82. color: $light-color;
  83. padding: $unit-1 $unit-2;
  84. position: absolute;
  85. user-select: none;
  86. }
  87. }
  88. @keyframes first-run {
  89. 0% {
  90. width: 0;
  91. }
  92. 25% {
  93. width: $unit-12;
  94. }
  95. 50% {
  96. width: $unit-4;
  97. }
  98. 75% {
  99. width: $unit-6;
  100. }
  101. 100% {
  102. width: 0;
  103. }
  104. }