每天一个Js小demo之移动端全景图场景实现-全景装修图。主要知识点:css3,旋转角度检测

<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width,user-scalable=no" />
<meta charset="UTF-8">
<title>Document</title>
<style type="text/css">
body,
html {
margin: 0;
height: 100%;
overflow: hidden;
position: relative;
}
.wrap {
position: relative;
height: 100%;
}
.view,
.boxZ,
.box {
position: absolute;
left: 50%;
top: 50%;
-webkit-transform-style: preserve-3d;
transform-style: preserve-3d;
}
.box {
-webkit-transform: rotateY(0deg);
transform: rotateY(0deg);
-webkit-animation: 36s rotate infinite linear;
animation: 36s rotate infinite linear;
}
.box span {
position: absolute;
left: 50%;
top: 50%;
margin: -512px 0 0 -512px;
width: 1024px;
height: 1024px;
text-align: center;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
/*
背面,角度和父级的角度相对的面是背景
*/
}
.box span:nth-of-type(1) {
-webkit-transform: rotateY(0deg) translateZ(-510px);
transform: rotateY(0deg) translateZ(-511px);
background: url(img/neg-x.png) no-repeat;
}
.box span:nth-of-type(2) {
-webkit-transform: rotateY(90deg) translateZ(-511px);
transform: rotateY(90deg) translateZ(-511px);
background: url(img/neg-z.png) no-repeat;
}
.box span:nth-of-type(3) {
-webkit-transform: rotateY(180deg) translateZ(-511px);
transform: rotateY(180deg) translateZ(-511px);
background: url(img/pos-x.png) no-repeat;
}
.box span:nth-of-type(4) {
background: url(img/pos-z.png) no-repeat;
-webkit-transform: rotateY(270deg) translateZ(-511px);
transform: rotateY(270deg) translateZ(-511px);
}
.box span:nth-of-type(5) {
background: url(img/pos-y.png);
-webkit-transform: rotateX(-90deg) translateZ(-511px);
transform: rotateX(-90deg) translateZ(-511px);
}
.box span:nth-of-type(6) {
background: url(img/neg-y.png);
-webkit-transform: rotateX(90deg) translateZ(-511px);
transform: rotateX(90deg) translateZ(-511px);
}
/*
transform-origin z轴的设置,在ios下有兼容问题
*/
#loading {
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 100%;
z-index: 10;
background: #fff url(img/loading.gif) no-repeat center center;
}
</style>
</head>
<body>
<div id="loading"></div>
<script type="text/javascript">
/* 检测图片加载完成 */
(function(){
var imgData = [
"img/neg-x.png",
"img/neg-y.png",
"img/neg-z.png",
"img/pos-x.png",
"img/pos-y.png",
"img/pos-z.png"
];
var nub = 0;
for(var i = 0; i < imgData.length; i++){
load(imgData[i]);
}
function load(url){
var img = new Image();
img.onload = function(){
nub++;
if(nub == imgData.length){
loading.style.display = "none";
}
};
img.src = url;
}
})();
</script>
<div class="wrap">
<div class="view">
<div class="boxZ">
<div class="box">
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="js/m.touch.js"></script>
<script type="text/javascript">
(function(){
setPerspective();
window.addEventListener(‘resize‘, function(e) {
setPerspective();
});
function setPerspective(){
var wrap = document.querySelector(‘.wrap‘);
var view = document.querySelector(‘.view‘);
var boxZ = document.querySelector(‘.boxZ‘);
var deg = 45;//视野夹角(角度越小,看到的范围越广,角度越大,看到的范围越少);
var Z = Math.round(Math.tan(deg*Math.PI/180)*wrap.clientHeight/2);//计算景深
wrap.style.perspective = wrap.style.WebKitPerspective = Z + "px";
//距离景物距离不变,那看到的画面大小就不变
css(view,"translateZ",Z);
css(boxZ,"translateZ",-100);
}
})();
(function(){
var box = document.querySelector(‘.box‘);
css(box,"rotateX",0);
css(box,"rotateY",0);
window.addEventListener(‘deviceorientation‘, function(e) {
var x = e.beta;
var y = e.gamma;
var z = e.alpha;
var rotateX = x - 90;
var rotateY = (y + z)%360;
if(rotateX > 60){
rotateX = 60;
} else if(rotateX <-60){
rotateX = -60;
}
css(box,"rotateX",rotateX);
css(box,"rotateY",-rotateY);
});
})();
//http://antario.act.qq.com/
</script>
</body>
</html>

时间: 2024-10-05 23:27:39

每天一个Js小demo之移动端全景图场景实现-全景装修图。主要知识点:css3,旋转角度检测的相关文章

每天一个JS 小demo之韩雪冬轮播图。主要知识点:html,css布局,对于数组和对象的理解和运用

1 @charset "utf-8"; 2 /* CSS Document */ 3 4 * { padding: 0; margin: 0; } 5 li { list-style: none; } 6 img { border: none; } 7 body { background: #ececec; padding-top: 50px; } 8 9 #automatic { width: 970px; height: 344px; position: relative; mar

每天一个JS 小demo之原生数组splice方法书写。主要知识点:锻炼思维逻辑能力,对于数组方法的理解和各种情况的考量

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head> <body><script>/** splice(start, deleteCount, data1, data2, data3...)* */ var arr = ['a', 'b'

每天一个JS 小demo之个人信息添加。主要知识点:DOM操作中的表格操作,节点操作

以下是简易效果: <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> table { width: 555px; text-align: center; } table a { text-decora

每天一个JS 小demo之自定义滚动条。主要知识点:事件应用

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style type="text/css">body { margin: 0;}#wrap { margin: 30px auto; position: relative; border: 1px s

每天一个JS 小demo之通过键盘方向键操作图片上下左右无缝切换。主要知识点:事件

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style type="text/css">.wrap { margin: 150px auto; position: relative; width: 400px; height: 300px; o

每天一个JS 小demo之通过事件委托实现菜单展开及选中特效。主要知识点:事件

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><style type="text/css">body { margin: 0; background: #f1f1f1;}p { margin: 0;} #dorpDown { position: r

每天一个JS 小demo之日历制作。主要知识点:日期函数和对于函数封装的灵活运用

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <style> td { text-align: center; } </style></head> <body> <p> <select id="yearS

每天一个JS 小demo之表单排序。主要知识点:DOM中的表单操作,节点操作

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Document</title><script type="text/javascript">window.onload = function(){ var input = document.querySelectorAll('inp

每天一个JS 小demo之邮件删除。主要知识点:事件应用

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title></title><style type="text/css">.wrap { width: 400px; margin: 30px auto;}ul { margin: 0; padding: 0; list-style: none;