Orientation example
How do I make an orientation example?
What is a orientation example? How do you make a orientation example? This script and codes were developed by Moreno Di Domenico on 09 January 2023, Monday.
Orientation example - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Orientation example</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <!-- Learn about this code on MDN: https://developer.mozilla.org/en-US/docs/Web/API/Detecting_device_orientation -->
<div class="garden"> <div class="ball"></div>
</div>
<pre class="output"></pre> <script src="js/index.js"></script>
</body>
</html>
Orientation example - Script Codes CSS Codes
.garden { position: relative; width : 200px; height: 200px; border: 5px solid #CCC; border-radius: 10px;
}
.ball { position: absolute; top : 90px; left : 90px; width : 20px; height: 20px; background: green; border-radius: 100%;
}
Orientation example - Script Codes JS Codes
var ball = document.querySelector('.ball');
var garden = document.querySelector('.garden');
var output = document.querySelector('.output');
var maxX = garden.clientWidth - ball.clientWidth;
var maxY = garden.clientHeight - ball.clientHeight;
function handleOrientation(event) { var x = event.beta; // In degree in the range [-180,180] var y = event.gamma; // In degree in the range [-90,90] output.innerHTML = "absolute : " + event.absolute + "\n"; output.innerHTML += "beta : " + x + "\n"; output.innerHTML += "gamma: " + y + "\n"; // Because we don't want to have the device upside down // We constrain the x value to the range [-90,90] if (x > 90) { x = 90}; if (x < -90) { x = -90}; // To make computation easier we shift the range of // x and y to [0,180] x += 90; y += 90; // 10 is half the size of the ball // It center the positioning point to the center of the ball ball.style.top = (maxX*x/180 - 10) + "px"; ball.style.left = (maxY*y/180 - 10) + "px";
}
//window.addEventListener('deviceorientation', handleOrientation);
Developer | Moreno Di Domenico |
Username | MorenoDiDomenico |
Uploaded | January 09, 2023 |
Rating | 3 |
Size | 2,205 Kb |
Views | 2,024 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
A Pen by Moreno Di Domenico | 2,096 Kb |
Canvas Wall | 2,909 Kb |
OwlCarousel | 2,186 Kb |
Bootstrap Clean Buttons | 4,469 Kb |
Dependency | 2,098 Kb |
CSS3 Explode Menu | 4,668 Kb |
Animations | 3,676 Kb |
ScrollInView | 2,307 Kb |
Interactive CSS3 iPhone 6 | 11,365 Kb |
Wheel of Fortune | 2,576 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Simple Carousel Pure CSS | Dangvanthanh | 4,080 Kb |
Brent Burns Tribute Page | Nevada48 | 2,569 Kb |
Jstam.com Home Page | Jstam | 10,558 Kb |
React JS Movie Info App | MTushar | 4,870 Kb |
A Pen by Shidhin | Shidhincr | 5,015 Kb |
Zeichensatz | Moklick | 2,058 Kb |
CSS Tooltips | Darylldoyle | 2,599 Kb |
A Pen by Bryan Rojas | Bryanrojas | 1,873 Kb |
SVG Transform vs CSS Transform | AmeliaBR | 4,175 Kb |
A Pen by utcwebdev | Utcwebdev | 2,856 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!