AnimationsTutorials

3D Box Animation

Tab Bar Animation

3D Box Animation

3D Box Animation

You can be use 3D Box Animation to animate a Logos, Icons, etc. and create user attractive UI components.

So if you are a person who wishes to develop a website, you have to know how to create 3D animations properly. Check out our tutorial and you can learn this techniques and use it on your web development. Below sections shows how to develop this animations.

How to create 3D Box Animation? We are here to solve your problem. In this article we discuss how to create a hover effect animations. Before we start please read the below articles which easier you to understand the process, if you are new to development.

Step 1 – Add HTML

It’s too easy and simple. Just copy and paste below code in your HTML editor between <body> </body> tag as below.

<body>
<h1><strong>3D Box</strong></h1>

    <section class="container">
        <div id="box" class="box show-front">
            <figure class="front"></figure>
            <figure class="back"></figure>
            <figure class="right"></figure>
            <figure class="left"></figure>
            <figure class="top"></figure>
            <figure class="bottom"></figure>
        </div>
    </section>

    <ul id="options">
        <li><button class="current show-front">Front</button></li>
        <li><button class="show-back">Back</button></li>
        <li><button class="show-right">Right</button></li>
        <li><button class="show-left">Left</button></li>
        <li><button class="show-top">Top</button></li>
        <li><button class="show-bottom">Bottom</button></li>
    </ul>
</body>

Step 2 – Add CSS

Copy and paste below code in your HTML editor between <style></style> tag as below.

<style>
        @import url("https://fonts.googleapis.com/css?family=Lato");

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

        body {
            text-align: center;
            background: #d8d7d9;
            padding: 20px;
            font-family: Lato;
            color: #fff;
        }

        h1 {
            font-weight: normal;
            font-size: 40px;
            font-weight: normal;
            text-transform: uppercase;
            margin: 20px 0 10px 10px;
        }

        h1 span {
            font-size: 13px;
            display: block;
            padding-left: 4px;
        }

        .container {
            width: 200px;
            height: 133.3333333333px;
            position: relative;
            margin: 40px auto;
            perspective: 1200px;
        }

        .box {
            width: 100%;
            height: 100%;
            position: absolute;
            transform-style: preserve-3d;
            transition: transform 0.5s;
        }

        .box figure {
            display: table;
            position: absolute;
            text-align: center;
            color: white;
        }

        .box .front,
        .box .back {
            width: 200px;
            height: 133.3333333333px;
        }

        .box .right,
        .box .left {
            width: 66.6666666667px;
            height: 133.3333333333px;
        }

        .box .top,
        .box .bottom {
            width: 200px;
            height: 66.6666666667px;
        }

        .box .right,
        .box .left {
            left: 66.6666666667px;
        }

        .box .top,
        .box .bottom {
            top: 33.3333333333px;
        }

        .box .front,
        .box .back {
            background: #3d9b5b;
        }

        .box .right,
        .box .left,
        .box .top,
        .box .bottom {
            background: #2f4d43;
        }

        .box .front {
            transform: translateZ(33.3333333333px);
        }

        .box .back {
            transform: rotateX(-180deg) translateZ(33.3333333333px);
        }

        .box .right {
            transform: rotateY(90deg) translateZ(100px);
        }

        .box .left {
            transform: rotateY(-90deg) translateZ(100px);
        }

        .box .top {
            transform: rotateX(90deg) translateZ(66.6666666667px);
        }

        .box .bottom {
            transform: rotateX(-90deg) translateZ(66.6666666667px);
        }

        .box.show-front {
            transform: translateZ(-33.3333333333px);
        }

        .box.show-back {
            transform: translateZ(-33.3333333333px) rotateX(-180deg);
        }

        .box.show-right {
            transform: translateZ(-100px) rotateY(-90deg);
        }

        .box.show-left {
            transform: translateZ(-100px) rotateY(90deg);
        }

        .box.show-top {
            transform: translateZ(-66.6666666667px) rotateX(-90deg);
        }

        .box.show-bottom {
            transform: translateZ(-66.6666666667px) rotateX(90deg);
        }

        .box:hover {
            transform: rotateX(-180deg) translateZ(33.3333333333px);
        }

        ul#options {
            list-style: none;
            display: table;
            margin-left: auto;
            margin-right: auto;
        }

        ul#options li {
            float: left;
            margin-right: 5px;
        }

        ul#options li button {
            outline: none;
            display: block;
            cursor: pointer;
            border: none;
            padding: 10px 20px;
            color: #fff;
            font-family: "Lato";
            text-transform: uppercase;
            font-size: 14px;
            background: #3d9b5b;
            border-radius: 2px;
            transition: all 0.2s ease-in;
        }

        ul#options li button:hover {
            background: #2f4d43;
        }

        ul#options li button.current {
            background: #2f4d34;
        }

        p.help {
            text-transform: uppercase;
            margin: 20px;
        }

        p.link {
            clear: both;
            margin-top: 40px;
        }

        p.link a {
            text-transform: uppercase;
            text-decoration: none;
            display: inline-block;
            color: #fff;
            padding: 5px 10px;
            margin: 0 5px;
            background-color: #3d9b5b;
            transition: all 0.2s ease-in;
        }

        p.link a:hover {
            background-color: #2f4d43;
        }
    </style>

At the end we will have something like this. You can change fonts, colors, backgrounds and all things that you want. Enjoy it.

Step 3 – Add JavaScript

Copy and paste below code in your HTML editor between <script></script> tag.

<script>
        /* REFERENCE: http://24ways.org/2010/intro-to-css-3d-transforms/  by David DeSandro */

        var init = function() {
            var box = document.querySelector('.box'),
                showPanelButtons = document.querySelectorAll('ul#options li button'),
                panelClassName = 'show-front',

                onButtonClick = function(event) {
                    console.log(box)
                    $(box).removeClass(panelClassName);
                    panelClassName = event.target.className;
                    $(box).addClass(panelClassName);
                };

            for (var i = 0, len = showPanelButtons.length; i < len; i++) {
                showPanelButtons[i].addEventListener('click', onButtonClick, false);
            }
        };

        window.addEventListener('DOMContentLoaded', init, false);

        //Only to Demo
        $('button').click(function() {
            $('ul#options li button').removeClass('current');
            $(this).addClass('current');
        });
    </script>

Out Put

Video Tutorial

Please watch this video to better understand this tutorial and don’t forget to subscribe to our channel.


Help others to find out about this article on Social Media sites. If you have any doubt or any problem, don’t hesitate to contact us. Thereafter we will be able to help you and also make sure you bookmark our site on your browser.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button