当前位置: 一起发展技术网 > 语言程序学习 > 文章正文

环形旋转图片展示效果 - 兼容FF(转自51js)

admin 发表于 2009-03-12 09:35 | 来源: | 阅读 614 views

平视效果

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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> 平视 </title>
 <!-- saved from url=(0011)about:blank -->
<base href="http://www.dhooo.com/web/images/" />
<style>
html,body{background:#990000;margin:0px; }
#pics_3d{
	position:absolute;
	height:300px;
	width:100%; 
	background:#000; 
	top:120px;
	border-bottom:20px solid #420000; 
	border-top:20px solid #420000; 
}
img{
	position:absolute;
	background:#eee; 
	left:0;top:0;
	border:5px solid #00CCFF;
 
}
</style>
 </head>
 
 <body>
 <div id="pics_3d">
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
 
 </div>
 </body>
<script >
 
/*
旋转子项类声明
*/
Item=function(UI){
 
	this.angle=0;
	this.UI=UI;
	this.update();
 
};
Item.ini={/*类静态属性(椭圆轨迹参数)*/
 
	axle_w:400,/* 半宽 */
	axle_h:10,/* 半高(视角高) */
	cen_x:500,/* 中心x */
	cen_y:260/* 中心y */
 
};
Item.prototype.update=function(){/* 按角度刷新UI */
 
	var J=this.UI.style,C=Item.ini,W=C.axle_w	,H=C.axle_h,X=C.cen_x,Y=C.cen_y;
	var angle=this.angle/180*Math.PI;/* 角度转弧度 */
	var left=Math.cos(angle)*W+X;
	var top=Math.sin(angle)*H+Y;
	var A=this.angle>270?this.angle-360:this.angle;
	var size=360-Math.abs(90-A)*3;/* 设置大小 */
	this.UI.width=Math.max(size,120);/* 下限 */
	var opacity=Math.max(10,size-180);/* 设置透明度 */
	J.filter='alpha(opacity='+opacity+')';
	J.opacity=opacity/100;
	J.left=(left-this.UI.offsetWidth/2)+'px';/* 设置位置 */
	top=(top-this.UI.offsetHeight)+'px';
	J.top=top;
	J.zIndex=parseInt(size*100);/* 设置Z序 */
 
};
 
/* 
菜单管理器 
*/
 
Nav_3D={
 
	items:[],
	dir:1,
	index:0,
	hover:false,
 
	add:function(item){
		this.items.push(item);
		item.index=this.items.length-1;
		item.UI.onclick=function (){
			var J=item.angle,M=Nav_3D;
			if(M.uping)return;
			if(J==90){
				return alert('goto new url..')
			};
			M.wheel_90(item);
			M.index=item.index;
		};
		item.UI.onmouseover=function (){
			if(item.angle==90){
				Nav_3D.hover=true;
				clearTimeout(Nav_3D.autoTimer);
			};
		};
		item.UI.onmouseout=function (){
			if(item.angle==90){
				Nav_3D.hover=false;
				Nav_3D.auto();
			};
		};
		return this;
	},
 
	wheel_90:function(hot){/* 把目标旋转到90度 */
		if(this.uping)return;
		this.uping=true;
		var This=this;
		this.timer=setInterval(function (){
			clearTimeout(This.autoTimer);/* 清除自动 */
			var A=hot.angle;
			This.dir=A<270&&A>90?-1:1;/* 确定旋转方向 */
			if(A==90){/* 旋转到指定位置时结束 */
				clearInterval(This.timer);
				This.uping=false;
				This.onEnd(hot);/* 自定义事件 */
			}
			if(A>270)A-=360;
			var set=Math.ceil(Math.abs((90-A)*0.1));/* 缓冲 */
			for (var i=0;i<This.items.length;i++ ) {
				var J=This.items[i];
				J.angle+= (set*This.dir);/* 角度自增 */
				J.update();
				if(J.angle>360)J.angle-=360;
				if(J.angle<0)J.angle +=360;
			};
		},15);
	},
 
	ready:function(){/* 自动设置初始角度 */
		var J=this.items,step=parseInt(360/J.length);
		for (var i=0;i<J.length;i++) {J[i].angle=i*step+90;}
		this.wheel_90(this.items[0]);/* 把第一个项目转到90度 */
		Nav_3D.prevHot=this.items[0].UI;
		Nav_3D.setHot();
	},
 
	setHot:function(isHot){/* 设置焦点样式 */
		if(!this.prevHot)return;
		with(this.prevHot.style){
			borderColor=isHot!==false?'#CC0000':'#00CCFF';
			cursor=isHot!==false?'default':"pointer";
		};
		return this;
	},
 
	auto:function(){/* 自动轮转 */
		this.index--;
		if(this.index<0)this.index=this.items.length-1;
		var J=this.items[this.index];
		this.setHot(false).prevHot=J.UI;
		this.setHot();
		this.wheel_90(J);
	},
 
	onEnd:function(hot){
		if(this.hover){
			return setTimeout(function(){Nav_3D.onEnd();},100);
		}
		this.autoTimer=setTimeout(function(){Nav_3D.auto();},1500);
	}
 
};
 
/*
Apply
*/
 
var imgs=document.getElementById("pics_3d").getElementsByTagName("IMG");
for (var i=0;i<imgs.length;i++ ) {
	Nav_3D.add(new Item(imgs[i]))
}
Nav_3D.ready();
 
</script>
</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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> 俯视 </title>
 <!-- saved from url=(0011)about:blank -->
<base href="http://www.dhooo.com/web/images/" />
<style>
html,body{background:#990000;margin:0px; }
#pics_3d{
	position:absolute;
	height:300px;
	width:100%; 
	background:#000; 
	top:120px;
	border-bottom:20px solid #420000; 
	border-top:20px solid #420000; 
}
img{
	position:absolute;
	background:#eee; 
	left:0;top:0;
	border:5px solid #00CCFF;
 
}
</style>
 </head>
 
 <body>
 <div id="pics_3d">
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />   
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
 </div>
 </body>
<script >
 
/*
旋转子项类声明
*/
Item=function(UI){
 
	this.angle=0;
	this.UI=UI;
	this.update();
 
};
Item.ini={/*类静态属性(椭圆轨迹参数)*/
 
	axle_w:400,/* 半宽 */
	axle_h:40,/* 半高(视角高) */
	cen_x:500,/* 中心x */
	cen_y:50/* 中心y */
 
};
Item.prototype.update=function(){/* 按角度刷新UI */
 
	var J=this.UI.style,C=Item.ini,W=C.axle_w	,H=C.axle_h,X=C.cen_x,Y=C.cen_y;
	var angle=this.angle/180*Math.PI;/* 角度转弧度 */
	var left=Math.cos(angle)*W+X;
	var top=Math.sin(angle)*H+Y;
	var A=this.angle>270?this.angle-360:this.angle;
	var size=360-Math.abs(90-A)*3;/* 设置大小 */
	this.UI.width=Math.max(size,120);/* 下限 */
	var opacity=Math.max(10,size-180);/* 设置透明度 */
	J.filter='alpha(opacity='+opacity+')';
	J.opacity=opacity/100;
	J.left=(left-this.UI.offsetWidth/2)+'px';/* 设置位置 */
	J.top=top+'px';
	J.zIndex=parseInt(size*100);/* 设置Z序 */
 
};
 
/* 
菜单管理器 
*/
 
Nav_3D={
 
	items:[],
	dir:1,
	index:0,
	hover:false,
 
	add:function(item){
		this.items.push(item);
		item.index=this.items.length-1;
		item.UI.onclick=function (){
			var J=item.angle,M=Nav_3D;
			if(M.uping)return;
			if(J==90){
				return alert('goto new url..')
			};
			M.wheel_90(item);
			M.index=item.index;
		};
		item.UI.onmouseover=function (){
			if(item.angle==90){
				Nav_3D.hover=true;
				clearTimeout(Nav_3D.autoTimer);
			};
		};
		item.UI.onmouseout=function (){
			if(item.angle==90){
				Nav_3D.hover=false;
				Nav_3D.auto();
			};
		};
		return this;
	},
 
	wheel_90:function(hot){/* 把目标旋转到90度 */
		if(this.uping)return;
		this.uping=true;
		var This=this;
		this.timer=setInterval(function (){
			clearTimeout(This.autoTimer);/* 清除自动 */
			var A=hot.angle;
			This.dir=A<270&&A>90?-1:1;/* 确定旋转方向 */
			if(A==90){/* 旋转到指定位置时结束 */
				clearInterval(This.timer);
				This.uping=false;
				This.onEnd(hot);/* 自定义事件 */
			}
			if(A>270)A-=360;
			var set=Math.ceil(Math.abs((90-A)*0.1));/* 缓冲 */
			for (var i=0;i<This.items.length;i++ ) {
				var J=This.items[i];
				J.angle+= (set*This.dir);/* 角度自增 */
				J.update();
				if(J.angle>360)J.angle-=360;
				if(J.angle<0)J.angle +=360;
			};
		},15);
	},
 
	ready:function(){/* 自动设置初始角度 */
		var J=this.items,step=parseInt(360/J.length);
		for (var i=0;i<J.length;i++) {J[i].angle=i*step+90;}
		this.wheel_90(this.items[0]);/* 把第一个项目转到90度 */
		Nav_3D.prevHot=this.items[0].UI;
		Nav_3D.setHot();
	},
 
	setHot:function(isHot){/* 设置焦点样式 */
		if(!this.prevHot)return;
		with(this.prevHot.style){
			borderColor=isHot!==false?'#CC0000':'#00CCFF';
			cursor=isHot!==false?'default':"pointer";
		};
		return this;
	},
 
	auto:function(){/* 自动轮转 */
		this.index--;
		if(this.index<0)this.index=this.items.length-1;
		var J=this.items[this.index];
		this.setHot(false).prevHot=J.UI;
		this.setHot();
		this.wheel_90(J);
	},
 
	onEnd:function(hot){
		if(this.hover){
			return setTimeout(function(){Nav_3D.onEnd();},100);
		}
		this.autoTimer=setTimeout(function(){Nav_3D.auto();},1500);
	}
 
};
 
/*
Apply
*/
 
var imgs=document.getElementById("pics_3d").getElementsByTagName("IMG");
for (var i=0;i<imgs.length;i++ ) {
	Nav_3D.add(new Item(imgs[i]))
}
Nav_3D.ready();
 
</script>
</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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title> 仰视 </title>
 <!-- saved from url=(0011)about:blank -->
<base href="http://www.dhooo.com/web/images/" />
<style>
html,body{background:#990000;margin:0px; }
#pics_3d{
	position:absolute;
	height:300px;
	width:100%; 
	background:#000; 
	top:120px;
	border-bottom:20px solid #420000; 
	border-top:20px solid #420000; 
}
img{
	position:absolute;
	background:#eee; 
	left:0;top:0;
	border:5px solid #00CCFF;
 
}
</style>
 </head>
 
 <body>
 <div id="pics_3d">
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />   
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
	  <img src="1.jpg" />  
	  <img src="2.jpg" />  
	  <img src="3.jpg" />  
	  <img src="4.jpg" />  
	  <img src="5.jpg" />  
 </div>
 </body>
<script >
 
/*
旋转子项类声明
*/
Item=function(UI){
 
	this.angle=0;
	this.UI=UI;
	this.update();
 
};
Item.ini={/*类静态属性(椭圆轨迹参数)*/
 
	axle_w:400,/* 半宽 */
	axle_h:-10,/* 半高(视角高) */
	cen_x:500,/* 中心x */
	cen_y:320/* 中心y */
 
};
Item.prototype.update=function(){/* 按角度刷新UI */
 
	var J=this.UI.style,C=Item.ini,W=C.axle_w	,H=C.axle_h,X=C.cen_x,Y=C.cen_y;
	var angle=this.angle/180*Math.PI;/* 角度转弧度 */
	var left=Math.cos(angle)*W+X;
	var top=Math.sin(angle)*H+Y;
	var A=this.angle>270?this.angle-360:this.angle;
	var size=360-Math.abs(90-A)*3;/* 设置大小 */
	this.UI.width=Math.max(size,100);/* 下限 */
	var opacity=Math.max(10,size-180);/* 设置透明度 */
	J.filter='alpha(opacity='+opacity+')';
	J.opacity=opacity/100;
	J.left=(left-this.UI.offsetWidth/2)+'px';/* 设置位置 */
	top=top-this.UI.offsetHeight*1.5;
	J.top=top+'px';
	J.zIndex=parseInt(size*100);/* 设置Z序 */
 
};
 
/* 
菜单管理器 
*/
 
Nav_3D={
 
	items:[],
	dir:1,
	index:0,
	hover:false,
 
	add:function(item){
		this.items.push(item);
		item.index=this.items.length-1;
		item.UI.onclick=function (){
			var J=item.angle,M=Nav_3D;
			if(M.uping)return;
			if(J==90){
				return alert('goto new url..')
			};
			M.wheel_90(item);
			M.index=item.index;
		};
		item.UI.onmouseover=function (){
			if(item.angle==90){
				Nav_3D.hover=true;
				clearTimeout(Nav_3D.autoTimer);
			};
		};
		item.UI.onmouseout=function (){
			if(item.angle==90){
				Nav_3D.hover=false;
				Nav_3D.auto();
			};
		};
		return this;
	},
 
	wheel_90:function(hot){/* 把目标旋转到90度 */
		if(this.uping)return;
		this.uping=true;
		var This=this;
		this.timer=setInterval(function (){
			clearTimeout(This.autoTimer);/* 清除自动 */
			var A=hot.angle;
			This.dir=A<270&&A>90?-1:1;/* 确定旋转方向 */
			if(A==90){/* 旋转到指定位置时结束 */
				clearInterval(This.timer);
				This.uping=false;
				This.onEnd(hot);/* 自定义事件 */
			}
			if(A>270)A-=360;
			var set=Math.ceil(Math.abs((90-A)*0.1));/* 缓冲 */
			for (var i=0;i<This.items.length;i++ ) {
				var J=This.items[i];
				J.angle+= (set*This.dir);/* 角度自增 */
				J.update();
				if(J.angle>360)J.angle-=360;
				if(J.angle<0)J.angle +=360;
			};
		},15);
	},
 
	ready:function(){/* 自动设置初始角度 */
		var J=this.items,step=parseInt(360/J.length);
		for (var i=0;i<J.length;i++) {J[i].angle=i*step+90;}
		this.wheel_90(this.items[0]);/* 把第一个项目转到90度 */
		Nav_3D.prevHot=this.items[0].UI;
		Nav_3D.setHot();
	},
 
	setHot:function(isHot){/* 设置焦点样式 */
		if(!this.prevHot)return;
		with(this.prevHot.style){
			borderColor=isHot!==false?'#CC0000':'#00CCFF';
			cursor=isHot!==false?'default':"pointer";
		};
		return this;
	},
 
	auto:function(){/* 自动轮转 */
		this.index--;
		if(this.index<0)this.index=this.items.length-1;
		var J=this.items[this.index];
		this.setHot(false).prevHot=J.UI;
		this.setHot();
		this.wheel_90(J);
	},
 
	onEnd:function(hot){
		if(this.hover){
			return setTimeout(function(){Nav_3D.onEnd();},100);
		}
		this.autoTimer=setTimeout(function(){Nav_3D.auto();},1500);
	}
 
};
 
/*
Apply
*/
 
var imgs=document.getElementById("pics_3d").getElementsByTagName("IMG");
for (var i=0;i<imgs.length;i++ ) {
	Nav_3D.add(new Item(imgs[i]))
}
Nav_3D.ready();
 
</script>
</html>
关键字:
喜欢一起发展技术网的文章,那就通过 RSS Feed 功能订阅阅读吧!

我要评论

*

* 绝不会泄露