<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Perspective Shift</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<div class="box"></div>
<div class="box"></div>
<div class="box"></div>
</div>
<script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
/*Downloaded from https://www.codeseek.co/matt-west/perspective-shift-kXALLa */
.container {
position: relative;
width: 400px;
margin: 100px auto;
}
.box {
width: 400px;
height: 200px;
background: red;
position: absolute;
top: 40px;
left: 0;
z-index: 3;
}
.box:nth-child(2) {
background: blue;
width: 340px;
height: 160px;
top: 20px;
left: 30px;
z-index: 2;
}
.box:nth-child(3) {
background: green;
width: 280px;
height: 140px;
top: 0;
left: 60px;
z-index: 1;
}
/*Downloaded from https://www.codeseek.co/matt-west/perspective-shift-kXALLa */
$(function() {
var boxTwo = document.querySelector('.box:nth-child(2)');
var boxThree = document.querySelector('.box:nth-child(3)');
if (window.DeviceOrientationEvent) {
window.addEventListener("deviceorientation", function(event) {
alert('okay');
var xValue = Math.round(event.gamma);
var yValue = Math.round(event.beta);
var Rotation = Math.round(event.alpha);
alert(xValue);
}, true);
}
});