当前位置:网站首页>The picture moves horizontally with the phone - gyroscope. 360 degree setting conditions
The picture moves horizontally with the phone - gyroscope. 360 degree setting conditions
2022-07-26 13:41:00 【Tangce】
explain :
The first one is : Simple version
Get the horizontal movement degree of the mobile phone
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style> body{ overflow: hidden; } .wrap{ position: relative; width: 100%; height: 100%; position: relative; transform: translate3d(0px, 0px, 0px); transform-style: preserve-3d; backface-visibility: hidden; } .bgimg{ position: absolute; } </style>
</head>
<body>
alpha:<span id="alpha"></span><br/>
beta:<span id="beta"></span><br/>
gamma:<span id="gamma"></span><br/>
<p class="translateZ">trarslateZ</p>
<div id="wrap" class="wrap">
<img class="bgimg" src="bgimg.png" alt="">
</div>
</body>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script> if (window.DeviceOrientationEvent) { window.addEventListener('deviceorientation', function (event) {
var a = document.getElementById('alpha'), b = document.getElementById('beta'), g = document.getElementById('gamma'), alpha = event.alpha, beta = event.beta, gamma = event.gamma; a.innerHTML = Math.round(alpha); b.innerHTML = Math.round(beta); g.innerHTML = Math.round(gamma); var translateZ=parseInt(Math.round(gamma)*10); $(".translateZ").html(translateZ); $(".wrap").css({ 'transform':'translateX('+translateZ+'px)' // 'transform': 'translateX(10px)' }) }, false); } else { document.querySelector('body').innerHTML = ' Your browser does not support gyroscopes '; } </script>
</html> The second kind : Complex version
Pictures move horizontally with the phone - gyroscope .360 Degree setting conditions
1. The initial position is the center , Turn left and right 90 degree , The picture is complete .
2. You can set the distance between the initial position of the picture and the center ( The main position part of the initial display picture )
var changeDeg90 = wrap_translateX / full_bgimgW; // initial , Offset degrees from the center
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style> .p6-wrap{ width: 100%; height: 100%; position: absolute; top: 0; right: 0; left: 0; overflow: hidden; } .p6fullView-wrap{ position: relative; width: 100%; height: 100%; position: relative; transform: translate3d(0px, 0px, 0px); transform-style: preserve-3d; backface-visibility: hidden; } .p6fullView-close-btn{ position: absolute; z-index: 2; right: 0; top: 0; } .p6fullView-wrap-text{ position: absolute; z-index: 2; top:50%; left: 50%; transform: translate(-50%,-50%); } .full-bgimg{ position: absolute; left: 50%; transform: translateX(-50%); /*width: 81.2rem;*/ /*height: 37.5rem;*/ /*width: 6867px;*/ width: 343.5rem; height: 100%; } </style>
</head>
<body>
alpha:<span id="alpha"></span><br/>
beta:<span id="beta"></span><br/>
gamma:<span id="gamma"></span><br/>
<p class="translateZ">trarslateZ</p>
<div class="p6-wrap">
<span class="p6fullView-close-btn">X</span>
<div class="p6fullView-wrap-text">
《
<span class="full_bgimgW"> Watch the panorama </span>
》
</div>
<div class="p6fullView-wrap">
<img class="full-bgimg" src="full-bgimg.jpg" alt="">
</div>
</div>
</body>
<script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script> // Panorama - gyroscope var flag=true; var firstAngle = 0; var instance = 0; var tuoluo = false;// Prevent event listening function deviceorientation(wrap_translateX) {
// Panorama - gyroscope var flag = true; var firstAngle = 0; var instance = 0; if (window.DeviceOrientationEvent) { window.addEventListener('deviceorientation', function(event) {
if (tuoluo) { var alpha = event.alpha, beta = event.beta, gamma = event.gamma; if (flag) { firstAngle = alpha; // Record first value flag = false; } var full_bgimgW = ($(".full-bgimg").width() - $(window).width()) / (2 * 90); // Every movement distance var translateZ = parseInt(Math.round(instance) * full_bgimgW) + wrap_translateX; var changeDeg90 = wrap_translateX / full_bgimgW; // initial , Offset degrees from the center /*1. According to the initial value firstAngle, Angle position judgment */ if (firstAngle > 90 && firstAngle < 270) { /*2. According to the offset angle greater than 90 degree , Judge */ if (alpha - firstAngle + changeDeg90 > 90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width()) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else if (alpha - firstAngle + changeDeg90 < -90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width() * (-1)) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { if (alpha > firstAngle) { instance = Math.abs(alpha - firstAngle); } else { instance = alpha - firstAngle; } } } else if (firstAngle < 90 && firstAngle > 0) { /* according to alpha The current position ,225 Degree is the critical point , Judge */ if (alpha > firstAngle && alpha < 225) { if (alpha - firstAngle + changeDeg90 > 90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width()) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { instance = Math.abs(alpha - firstAngle); } } else if (alpha < firstAngle && alpha > 0) { if (alpha - firstAngle + changeDeg90 < -90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width() * (-1)) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { instance = Math.abs(alpha - firstAngle) * (-1); } } else if (alpha < 360 && alpha > 225) { if ((alpha - 360 - firstAngle + changeDeg90) < -90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width() * (-1)) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { instance = Math.abs(alpha - 360 - firstAngle) * (-1); } } } else if (firstAngle < 360 && firstAngle > 270) { /* according to alpha The current position ,135 Degree is the critical point , Judge */ if (alpha < firstAngle && alpha > 135) { if (alpha - firstAngle + changeDeg90 < -90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width() * (-1)) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { instance = Math.abs(alpha - firstAngle) * (-1); } } else if (alpha > firstAngle && alpha < 360) { if ((alpha - firstAngle + changeDeg90) > 90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width()) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { instance = Math.abs(alpha - firstAngle); } } else if (alpha < 135 && alpha > 0) { if ((360 - firstAngle + alpha + changeDeg90) > 90) { var full_bgimgW = ($(".full-bgimg").width() - $(window).width()) / 2; $(".p6fullView-wrap").css({ 'transform': 'translateX(' + full_bgimgW + 'px)' }); } else { instance = Math.abs(360 - firstAngle + alpha); } } } $(".full_bgimgW").html(" Initial degree :" + firstAngle + " Current degrees :" + alpha + " Degree of deviation from the center " + changeDeg90 + " Offset distance " + translateZ + " Every degree px" + full_bgimgW) // $(".translateZ").html(translateZ); // if(instance > 0 && instance < 90){
$(".p6fullView-wrap").css({ 'transform': 'translateX(' + translateZ + 'px)' }) // } } }, false); } else { document.querySelector('body').innerHTML = ' Your browser does not support gyroscopes '; } } </script>
</html>边栏推荐
- The last time I heard about eBay, or the last time
- Basic sentence structure of English ----- origin
- Frisbee, 2022 "black red" top stream
- Parent class reference to child class (parent class reference points to child class object)
- LCL three-phase PWM rectifier (inverter)
- AI theory knowledge map 1 Foundation
- Segmentation fault (core dumped)
- [beauty of open source] nanomsg (2): req/rep mode
- 421. Maximum XOR value of two numbers in the array
- Precautions for triggering pytest.main() from other files
猜你喜欢

The last time I heard about eBay, or the last time

MVVM architecture encapsulation of kotlin series (kotlin+mvvm)

Detailed relation extraction model casrel

Win11+VS2019配置YOLOX

Feixin, which lasted 15 years and had 500million users, was completely dead

白帽子揭秘:互联网千亿黑产吓退马斯克

JSON data transfer parameters & date type parameter transfer

Why does WPS refuse advertising?

详解关系抽取模型 CasRel
![[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light](/img/99/6581b8a576e59a13aa4e977e3a1b70.jpg)
[flower carving hands-on] fun music visualization series small project (12) -- meter tube fast rhythm light
随机推荐
Ros2 learning (1) introduction to ros2
MVVM architecture encapsulation of kotlin series (kotlin+mvvm)
B+ tree selection index (1) -- MySQL from entry to proficiency (22)
[flower carving hands-on] interesting and fun music visualization series small project (13) -- organic rod column lamp
Multi objective optimization series 1 --- explanation of non dominated sorting function of NSGA2
[shaders realize overlay to re cover cross dressing effect _shader effect Chapter 9]
JUC总结
Why does WPS refuse advertising?
Square root of leetcode 69. x
Implementation of SAP ABAP daemon
图扑 3D 可视化国风设计 | 科技与文化碰撞炫酷”火花“
How to build a customer-centric product blueprint: suggestions from the chief technology officer
终极套娃 2.0 | 云原生交付的封装
Exploration on cache design optimization of community like business
Propagation of transactions
Team research and development from ants' foraging process (Reprint)
[turn] judge the relationship between two geometries in ArcGIS
【Oauth2】五、OAuth2LoginAuthenticationFilter
[oauth2] VIII. Configuration logic of oauth2 login -oauth2loginconfigurer and oauth2clientconfigurer
This article explains the FS file module and path module in nodejs in detail