HOME  >   CSS3 ANIMATION  >   CSS3 3D Cube Focus Image Animation
CSS3 3D Cube Focus Image Animation
BY William7 Jan,2021

Today we are going to continue to share here a CSS3 based focus map plugin, which features an image switching container that is a 3D cube that renders that image in front of the cube when you click on the image.


CSS3 3D Cube Focus Image Animation
HTML Body Code
<div class="cube-container">

	<div class="cube initial-position">

		<img class="cube-face-image image-1" src="images/p1300.jpg">
		<img class="cube-face-image image-2" src="images/p2300.jpg">
		<img class="cube-face-image image-3" src="images/p3300.jpg">
		<img class="cube-face-image image-4" src="images/p4300.jpg">
		<img class="cube-face-image image-5" src="images/p5300.jpg">
		<img class="cube-face-image image-6" src="images/p6300.jpg">

<h2>Click the images below to rotate the cube</h2>

<div class="image-buttons">

	<input type="image" class="show-image-1" src="images/p1100.jpg"></input>

	<input type="image" class="show-image-2" src="images/p2100.jpg"></input>

	<input type="image" class="show-image-3" src="images/p3100.jpg"></input>

	<input type="image" class="show-image-4" src="images/p4100.jpg"></input>

	<input type="image" class="show-image-5" src="images/p5100.jpg"></input>

	<input type="image" class="show-image-6" src="images/p6100.jpg"></input>

Css Code
body {
	font-family: "Montserrat", Arial, sans-serif;
	font-weight: 500;
	line-height: 1.5;
	text-align: center;
	min-height: 100vh;
	padding: 4rem 2rem;
	color: #fafafa;
	background-color: #080808;

h1 {
	font-size: 4rem;

h2 {
	font-size: 2rem;
	margin-bottom: 2.5rem;

.cube-container {
	position: relative;
	width: 30rem;
	height: 30rem;
	margin: 5rem auto 6rem;
	perspective: 100rem;

.cube {
	position: absolute;
	width: 100%;
	height: 100%;
	transform-style: preserve-3d;
	transition: transform 1s cubic-bezier(0.32, 0.05, 0.35, 1.6);
Js Code
window.addEventListener("DOMContentLoaded", function () {

	var cube = document.querySelector(".cube"),
	    imageButtons = document.querySelector(".image-buttons");
	var cubeImageClass = cube.classList[1];

	imageButtons.addEventListener("click", function (e) {

		var targetNode = e.target.nodeName,
		    targetClass = e.target.className;

		if (targetNode === "INPUT" && targetClass !== cubeImageClass) {

			console.log("Show Image: " + targetClass.charAt(11));

			cube.classList.replace(cubeImageClass, targetClass);

			cubeImageClass = targetClass;