LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Welcome

CSS
html, body, * {
	margin: 0;
	padding: 0;
}

html, body {
    overflow: hidden;   
}

html {
    background-color: #272727;
    color: white;
}

body {
    perspective: 1000px;
    font-size: 16px;
    line-height: 1.5;
}

html, body, #login {
    width: 100%;
    height: 100%;
}
#login {
    -webkit-transform-style: preserve-3d;
    transform-style: preserve-3d;
}

#login div, #login form {
    position: absolute;
    margin: auto;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    display: block;
    background-color: aqua;
    box-shadow: 0 0 150px cyan;
    border: 1px solid #00e0e0;
}

#loginForm {
    width: 500px;
    height: 300px;
}

#login .top {
    width: 500px;
    height: 100px;
    -webkit-transform: translateY(-150px) translateZ(-50px) rotateX(90deg);
    transform: translateY(-150px) translateZ(-50px) rotateX(90deg);
}

#login .left {
    width: 100px;
    height: 300px;
    -webkit-transform: translateX(-250px) translateZ(-50px) rotateY(90deg);
    transform: translateX(-250px) translateZ(-50px) rotateY(90deg);
}

#login .right {
    width: 100px;
    height: 300px;
    -webkit-transform: translateX(250px) translateZ(-50px) rotateY(90deg);
    transform: translateX(250px) translateZ(-50px) rotateY(90deg);
}

#login .bottom {
    width: 500px;
    height: 100px;
    -webkit-transform: translateY(150px) translateZ(-50px) rotateX(90deg);
    transform: translateY(150px) translateZ(-50px) rotateX(90deg);
}

#login .back {
    width: 500px;
    height: 300px;
    -webkit-transform: translateZ(-100px) rotateY(180deg) rotate(180deg);
    transform: translateZ(-100px) rotateY(180deg) rotate(180deg);
}

#login .back h1 {
    line-height: 300px;
    text-align: center;
    vertical-align: middle;
    transition: 0.25s 1s ease opacity;
}

#loginForm input {
    display: block;
    border: none;
    outline: none;
}

#loginForm input[type="text"], #loginForm input[type="password"] {
    width: 300px;
    height: 20px;
    margin: 10px auto;
    padding: 15px 30px;
    box-shadow: inset 0 0 10px cyan;
}

#loginForm input[type="text"] {
    margin-top: 70px;
}

#login .submit {
    display: block;
    margin: 30px auto;
    background-color: transparent;
    box-shadow: inset 0 0 10px #00afaf;
    cursor: pointer;
    border: none;
    transition: .2s box-shadow, .2s ease color;
}

#login .submit a {
    display: block;
    color: #007b7b;
    text-decoration: none;
    padding: 20px 50px;
}

#login .submit:hover {
    box-shadow: inset 0 0 100px #00afaf;
    color: white;
}

@-webkit-keyframes rotate {
    0% {
        -webkit-transform: rotateX(0);
    }
    100% {
        -webkit-transform: rotateX(180deg);
    }
}

@keyframes rotate {
    0% {
        transform: rotateX(0);
    }
    100% {
        transform: rotateX(180deg);
    }
}

#login:target {
    -webkit-animation: 2s ease rotate forwards;  
    animation: 2s ease rotate forwards;
}
JS
function getMousePosition(e) {
	var x, y = 0;
	if (e.pageX && e.pageY) {
		x = e.pageX;
		y = e.pageY;
	}else if (e.clientX && e.clientY) {
		x = e.clientX + (document.documentElement.scrollLeft ?
			document.documentElement.scrollLeft :
			document.body.scrollLeft);
		y = e.clientY + (document.documentElement.scrollTop ?
			document.documentElement.scrollTop :
			document.body.scrollTop);
	}
   	return {
		x: x,
		y: y
	}
}

function updateLoginBoxRotation(elem, ry, rx) {
	var factor = 30;
	rx = -( (rx > 0.5) ?  (rx-0.5)*2 : -(1-rx-0.5)*2) * factor;
	ry = -( (ry > 0.5) ? -(ry-0.5)*2 :  (1-ry-0.5)*2) * factor;
    var accuracy = 10;
    rx = Math.round((rx)*accuracy)/accuracy;
    ry = Math.round((ry)*accuracy)/accuracy;
	var transform = 'rotateX('+rx+'deg) rotateY('+ry+'deg)';
	elem.style.webkitTransform = transform;
    elem.style.transform = transform;
}

function init() {
  rotate = true;
    var loginBox = document.getElementById('login');
    window.onmousemove = function(e) {
      if (rotate) {
      var mPOS = getMousePosition(e);
      updateLoginBoxRotation(loginBox, mPOS.x/window.innerWidth, mPOS.y/window.innerHeight);
    }
	}
}

document.addEventListener("DOMContentLoaded", init, false);
Host Instantly Drag and Drop Website Builder

 

Description

A real 3D Box using CSS 3D Transforms and Javascript to face the mouse position.
Term
Wed, 11/29/2017 - 11:23

Related Codes

Pen ID
Pen ID
Pen ID