JSFiddle - React, Tailwind, and code Playground

by annndrewww

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/css/all.min.css"
    />
    <link rel="stylesheet" href="style.css" />
    <title>Слайдер | Проект 3</title>
  </head>
  <body>
    <div class="container">
      <div class="sidebar">
        <div style="background: rgb(2,0,36);
        background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(190,190,190,1) 0%, rgba(249,249,249,1) 100%);">
          <h1>Snow in the desert</h1>
          <p>Love, death & robots</p>
        </div>
        <div style="background: rgb(2,0,36);
        background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(208,45,171,1) 0%, rgba(255,97,219,1) 100%);">
          <h1>Life Hutch</h1>
          <p>Love, death & robots</p>
        </div>
        <div style="background: linear-gradient(221.87deg, #8308EA 1%, #5305AF 128%);">
          <h1>Zima Blue</h1>
          <p>Love, death & robots</p>
        </div>
        <div style="background: rgb(2,0,36);
        background: linear-gradient(90deg, rgba(2,0,36,1) 0%, rgba(11,59,139,1) 0%, rgba(14,81,193,1) 100%);">
          <h1>Automated Customer Service</h1>
          <p>Love, death & robots</p>
        </div>
      </div>
      <div class="main-slide">
        <div
          style="
            background-image: url('https://images.unsplash.com/photo-1602254015557-15e0ad50beea?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=1500&q=80');
          "
        ></div>
        <div
          style="
            background-image: url('https://images.unsplash.com/photo-1605648916361-9bc12ad6a569?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=750&q=80');
          "
        ></div>
        <div
          style="
            background-image:...

CSS

@import url('https://fonts.googleapis.com/css?family=Roboto&display=swap');

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Roboto', sans-serif;
  height: 100vh;
}

.container {
  position: relative;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
}

.sidebar {
  height: 100%;
  width: 35%;
  position: absolute;
  top: 0;
  left: 0;
  transition: transform 0.5s ease-in-out;
}

.sidebar > div {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #fff;
}

.sidebar h1 {
  font-size: 40px;
  margin-bottom: 10px;
  margin-top: -30px;
}

.main-slide {
  height: 100%;
  position: absolute;
  top: 0;
  left: 35%;
  width: 65%;
  transition: transform 0.5s ease-in-out;
}

.main-slide > div {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center center;
  height: 100%;
  width: 100%;
}

button {
  background-color: #fff;
  border: none;
  color: #aaa;
  cursor: pointer;
  font-size: 16px;
  padding: 15px;
}

button:hover {
  color: #222;
}

button:focus {
  outline: none;
}

.container .controls button {
  position: absolute;
  left: 35%;
  top: 50%;
  z-index: 100;
}

.container .controls .down-button {
  transform: translateX(-100%);
  border-top-left-radius: 5px;
  border-bottom-left-radius: 5px;
}

.container .controls .up-button {
  transform: translateY(-100%);
  border-top-right-radius: 5px;
  border-bottom-right-radius: 5px;
}

JavaScript

const upBtn = document.querySelector('.up-button'); // Получаем селектор класса .up-button в JS
const downBtn = document.querySelector('.down-button'); // Тоже самое что и первое
const sidebar = document.querySelector('.sidebar'); // Цветной фон слева
const mainSlide = document.querySelector('.main-slide'); // Тоже самое
const slidesCount = mainSlide.querySelectorAll('div').length;
const container = document.querySelector('.container');

let activeSlideIndex = 0

sidebar.style.top = `-${(slidesCount - 1) * 100}vh`;

upBtn.addEventListener('click', () => {
    changeSlide('up')
})

downBtn.addEventListener('click', () => {
    changeSlide('down')
})

function changeSlide(direction) {
    if(direction === 'up') {
        activeSlideIndex++
        if(activeSlideIndex === slidesCount) {
            activeSlideIndex = 0
        }

    }

    else if(direction === 'down') {
        activeSlideIndex--
        if(activeSlideIndex < 0) {
            activeSlideIndex = slidesCount - 1
        }
    }

    const height = container.clientHeight;

    mainSlide.style.transform = `translateY(-${activeSlideIndex * height}px)`; 
    sidebar.style.transform = `translateY(${activeSlideIndex * height}px)`;
}