Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="slider">
  <img class="slide before" src="https://lipsum.app/id/3/600x300" alt="Картинка 1">
  <img class="slide after" src="https://lipsum.app/id/3/600x300" alt="Картинка 2">
  <input type="range" min="0" max="100" value="50" aria-label="Percentage of before photo shown" class="range">
  <!--  как только будет нормальная поддержка :has, пустой div можно будет убрать и заменить на псевдо от первого слайда или от общей обертки. Доступно после декабря 2023, т.е. уже можно менять ;) -->
  <div class="button-line" aria-hidden="true"></div>
</section>
<output>50%</output>
<hr>
<p>Самый простой вариант для кнопки. Берем из макета всю svg, разбираемся какая деталька в ней за что отвечает, изменяем цвета. Круглях делаем белым, остальному задаем currentColor.И будем менять color у кнопки. (Можно и через свойство fill, если больше хочется). Только не нужно так называть класс кнопки.</p>
<button class="slider-mega-btn">
  <svg width="40" height="512" viewBox="0 0 40 512" fill="none" xmlns="http://www.w3.org/2000/svg">
    <rect x="18" width="4" height="512" rx="2" fill="currentColor"></rect>
    <rect x="1" y="237" width="38" height="38" rx="19" stroke="currentColor" stroke-width="2" fill="#ffffff"></rect>
    <path d="M16 247L8 256L16 265V247Z" fill="currentColor"></path>
    <path d="M32 256L24 247V265L32 256Z" fill="currentColor"></path>
  </svg>
</button>
<p><a href="https://codepen.io/firefoxic/pen/VwXywgW">Вариант Сергея</a></p>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Mulish&display=swap");

body {
  font-family: Mulish, sans-serif;
  background: #bebebe;
}

.slider {
  display: grid;
  grid-template-columns: var(--persent, 50%) 1fr;
  width: 600px;
  margin: 50px auto;
}

.slide {
  grid-row: 1/2;
  object-fit: cover;
}

.before {
  grid-column: 1/2;
  object-position: left;
}

.after {
  grid-column: 2/3;
  object-position: right;
  filter: grayscale(1);
  z-index: -1; /*нужен только из-за filter*/
}

.range {
  grid-column: 1/-1;
  grid-row: 1/2;
  height: 100%;
  margin: 0;
  opacity: 0;
}

.button-line {
  grid-column: 1/2;
  grid-row: 1/2;
  justify-self: end;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 4px;
  transform: translateX(50%);
  background: deepskyblue;
  pointer-events: none;
}

.button-line::after {
  content: "❮ ❯";
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  border: 3px solid deepskyblue;
  border-radius: 50%;
  box-sizing: border-box;
  line-height: 1;
  font-size: 20px;
  color: white;
  background: deepskyblue;
}

.range:active + .button-line::after {
  color: deepskyblue;
  background: white;
}

.range:focus-visible + .button-line::after {
  color: red;
  background: white;
}

img {
  /* на случай отвалившихся картинок*/
  width: 100%;
  height: 300px;
  background: #00d4ff;

  &::after {
    content: "Если нет картинок, включи VPN. Впрочем, и без них понятно что к чему";
    display: block;
    padding-left: 10px;
    padding-right: 10px;
    font-size: 0.8em;
  }
}

.slider-mega-btn {
  border: none;
  color: deepskyblue;
  background: none;

  &:hover {
    color: deeppink;
  }
}

              
            
!

JS

              
                function initCatSlider() {
  const container = document.querySelector('.slider');
  document.querySelector('.range').addEventListener('input', (e) => {
    container.style.setProperty('--persent', `${e.target.value}%`);
    document.querySelector('output').innerHTML = `${e.target.value}%`;
  });
}

initCatSlider();
              
            
!
999px

Console