ADVERTISEMENT

3D Cube Image Slider using HTML, CSS & JavaScript

Telegram Group Join Now

ADVERTISEMENT

3D Cube Image Slider using HTML, CSS & JavaScript

Hello everyone. Welcome to today’s tutorial on Codewithrandom. We’ll learn how to make 3D Cube Image Slider which will . In Today’s session, We will use HTML, CSS, and JavaScript to complete this 3D Cube Image Slider Project.

ADVERTISEMENT

Project Description

ADVERTISEMENT

Step 1
The HTML (Hypertext Markup Language) will help us to create the structure for the list with some necessary attributes and elements to make 3D Cube Image Slider Project.

Step 2
Then we will use CSS (Cascading Stylesheet) which will help us to style or design the project with suitable padding and alignment in the 3D Cube Image Slider Project.

ADVERTISEMENT

Step 3
At last we will use JS (JavaScript) which will add a logic to make the 3D Cube Image Slider responsive from the user end.

ADVERTISEMENT

I hope you have got an idea about the project.

HTML Code for 3D Cube Image Slider

First we’ll start with creating the structure of the 3D Cube Image Slider project for that as you can see the above code we have used all the necessary elements & attributes to setup the structure. Let us know code the CSS part to add styling and aligned the tags.

<html lang="en">
  <head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>3D Cube Slider</title>
    <!-- Font Awesome -->
    <link
      rel="stylesheet"
      href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css"
    />
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="wrapper">
      <div class="container">
        <div class="image-cube">
          <div class="front">
            <img src="https://images.unsplash.com/photo-1613068687893-5e85b4638b56?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" />
          </div>
          <div class="right">
            <img src="https://images.unsplash.com/photo-1618477247222-acbdb0e159b3?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80" />
          </div>
          <div class="back">
            <img src="https://images.unsplash.com/photo-1573164574230-db1d5e960238?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1769&q=80" />
          </div>
          <div class="left">
            <img src="https://images.unsplash.com/photo-1618477371303-b2a56f422d9e?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=764&q=80" />
          </div>
        </div>
      </div>
      <div class="btns">
        <button id="prev">
          <i class="fas fa-arrow-left"></i>
        </button>
        <button id="next">
          <i class="fas fa-arrow-right"></i>
        </button>
      </div>
    </div>
    <!-- Script -->
    <script src="script.js"></script>
  </body>
</html>

50+ HTML, CSS & JavaScript Projects With Source Code

ADVERTISEMENT

CSS Code for 3D Cube Image Slider

Second comes the CSS code in which we have styled for the structure we have padded as well as aligned the 3D Cube Image Slider project so that it is properly situated and doesn’t get messy with suitable CSS elements. Now lets code the JavaScript part to make responsive.

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}
body {
  background-color: #000000;
}
.wrapper {
  border: 1px solid #ffffff;
  height: 300px;
  width: 300px;
  position: absolute;
  margin: auto;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
}
.container {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  perspective: 800px;
  perspective-origin: 50%;
}
.image-cube {
  width: 350px;
  height: 350px;
  transform-style: preserve-3d;
  position: relative;
  transition: 2s;
}
.image-cube div {
  height: 300px;
  width: 300px;
  position: absolute;
}
img {
  width: 100%;
  transform: translateZ(0);
}
.front {
  transform: translateZ(150px);
}
.right {
  transform: rotateY(-270deg) translateX(150px);
  transform-origin: 100% 0;
}
.back {
  transform: translateZ(-150px) rotateY(180deg);
}
.left {
  transform: rotateY(270deg) translateX(-150px);
  transform-origin: 0 50%;
}
.btns {
  margin-top: 80px;
  display: flex;
  justify-content: space-between;
}
.btns button {
  background-color: transparent;
  color: #ffffff;
  border: 3px solid #ffffff;
  padding: 8px 40px;
  border-radius: 30px;
  font-size: 20px;
  cursor: pointer;
}

JavaScript Code for 3D Cube Image Slider

Last stage of the project the JavaScript in which we have added the logical and coded as per the requirement with some conditions. This is a simple JavaScript code in which we have just made the button functional so that it can rotate the cube of images. Let us see the Final Output of the project 3D Cube Image Slider using HTML, CSS & JavaScript (Source Code).

let cube = document.querySelector(".image-cube");
let btnNext = document.getElementById("next");
let btnPrev = document.getElementById("prev");

let pos = 0;

btnNext.addEventListener("click", () => {
  pos -= 90;
  cube.style.transform = `rotateY(${pos}deg)`;
});
btnPrev.addEventListener("click", () => {
  pos += 90;
  cube.style.transform = `rotateY(${pos}deg)`;
});

5+ HTML CSS Projects With Source Code

ADVERTISEMENT

Final Output


We have Successfully created our 3D Cube Image Slider using HTML, CSS & JavaScript (Source Code). You can use this project for your personal needs and the respective lines of code are given with the code pen link mentioned above.

ADVERTISEMENT

If you find out this Blog helpful, then make sure to search code with random on google for Front End Projects with Source codes and make sure to Follow the Code with Random Instagram page.

Code Idea – codingartist

Written By – Harsh Sawant

Code By – @harshh9

ADVERTISEMENT

ADVERTISEMENT

Telegram Group Join Now

Share on:

Leave a Comment

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT