-
Notifications
You must be signed in to change notification settings - Fork 1
/
h5_3Dcorridor.html
169 lines (142 loc) · 5.18 KB
/
h5_3Dcorridor.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
* {margin:0; padding:0;}
body {background:black; overflow:hidden;}
#div1 {position:absolute; left:50%; top:50%; margin-left:-0px; margin-top:-360px;}
.item {position:relative; width:510px; height:720px; margin:0 80px; float:left;}
.item .img {position:absolute; top:0; left:0;width:510px; height:720px;}
.item .img_r {position:absolute; top: 735px; left:0; width:100%; height:100%; -webkit-transform:scaleY(-1); -moz-transform:scaleY(-1);opacity:0.3;}
#copyright {position:absolute; bottom: 20px; width:100%; text-align:center;}
#copyright a {color:#CCC; text-decoration:none;}
#copyright a:hover {text-decoration:underline;}
#loading {position:absolute; left:0; top:50%; width:100%; color:white; text-align:center;}
</style>
<title>带倒影的3D图片走廊(demo)</title>
<script>
var aImg=['image/taobao_img1.jpg', 'image/taobao_img2.jpg', 'image/taobao_img3.jpg', 'image/taobao_img4.jpg', 'image/taobao_img5.jpg'];
window.onload=function ()
{
preloadImgs(aImg, loaded, function (){
alert('图片加载失败,请刷新重试');
}, function (pre){
document.getElementById('loading').getElementsByTagName('span')[0].innerHTML=pre+'%'+'请在chrome浏览器下观看';
});
};
function preloadImgs(arr, fnSucc, fnFaild, fnProgress)
{
var loaded=0;
for(var i=0;i<arr.length;i++)
{
var oImg=new Image();
oImg.onload=function (){
loaded++;
fnProgress&&fnProgress(100*loaded/arr.length);
if(loaded==arr.length)fnSucc&&fnSucc();
this.onload=this.onerror=null;
this.src='';
};
oImg.onerror=function ()
{
fnFaild&&fnFaild(this.src);
fnFaild=fnSucc=fnProgress=null;
};
oImg.src=arr[i];
}
}
function loaded()
{
document.getElementById('loading').style.display='none';
var oDiv=document.getElementById('div1');
var aDiv=[];
var MAX_DEG_X=30;
var MAX_DEG_Y=15;
var x=0,y=0;
var iLastDoMove=0;
var i=0;
var timer=null;
oDiv.style.width=aImg.length*670+'px';
oDiv.style.marginLeft=-oDiv.offsetWidth/2+'px';
for(i=0;i<aImg.length;i++)
{
var oNewDiv=document.createElement('div');
oNewDiv.innerHTML='<img class="img" /><div class="img_r"></div>';
var oImg=oNewDiv.getElementsByTagName('img')[0];
var oImgR=oNewDiv.getElementsByTagName('div')[0];
oImgR.style.background='-webkit-linear-gradient(top, rgba(0,0,0,1) 60%, rgba(0,0,0,0)), url('+aImg[i]+')';
oImg.src=aImg[i];
oNewDiv.className='item';
oDiv.appendChild(oNewDiv);
aDiv.push(oNewDiv);
}
// (function (){
// var oS=document.createElement('script');
//
// oS.type='text/javascript';
// oS.src='http://www.zhinengshe.com/zpi/zns_demo.php?id=3516';
//
// document.body.appendChild(oS);
// })();
document.onmousemove=function (ev)
{
var oEvent=ev||event;
var oDiv=document.getElementById('div1');
/*x=oEvent.clientX;
y=oEvent.clientY;*/
startMove(oEvent.clientX, oEvent.clientY);
//document.getElementById('txt1').value=rx;
};
function startMove(iX, iY)
{
clearInterval(timer);
iNow=new Date().getTime();
if(iNow-iLastDoMove>30)
{
doMove();
iLastDoMove=iNow;
}
timer=setInterval(doMove, 30);
function doMove()
{
if(x==iX && y==iY)
{
clearInterval(timer);
}
else
{
iSpeed=(iX-x)/8;
iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
x+=iSpeed;
iSpeed=(iY-y)/8;
iSpeed=iSpeed>0?Math.ceil(iSpeed):Math.floor(iSpeed);
y+=iSpeed;
}
var w=document.documentElement.clientWidth;
var h=document.documentElement.clientHeight;
//var w=600;
//var h=600;
var dis=Math.sqrt(Math.pow(x-w/2,2)+Math.pow(y-h/2,2));
var rx=(x-w/2)*2/w;
var ry=-(y-h/2)*2/h;
var tx=-rx*oDiv.offsetWidth/2;
var ty=ry*100;
//var scale=1-(dis/1000);
var scale=0.6*(1-Math.abs(y-h/2)/h);
oDiv.style.WebkitTransform='perspective(1000px) rotateY('+MAX_DEG_X*rx+'deg) rotateX('+MAX_DEG_Y*ry+'deg) scale('+scale+') translate('+tx+'px,'+ty+'px)';
}
}
}
</script>
</head>
<body>
<div id="loading">
<span>0%--请在chrome浏览器下观看</span>
</div>
<div id="div1"></div>
<div id="copyright">
<a href="index.html" target="_blank">author:Crise,tel:15179819149</a>
</div>
</body>
</html>