Javascript应用--窗户里的图片展示效果(图片换成自己的即可运行)

Code:
  1. <!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>4</title>
  5. <metahttp-equiv="imagetoolbar"content="no">
  6. <styletype="text/css">
  7. body{
  8. background:#222;
  9. overflow:hidden;
  10. left:0;
  11. top:0;
  12. width:100%;
  13. height:100%;
  14. margin:0;
  15. padding:0;
  16. }
  17. #screenimg{
  18. position:absolute;
  19. visibility:hidden;
  20. }
  21. #screenspan{
  22. position:absolute;
  23. background:#fff;
  24. cursor:pointer;
  25. visibility:hidden;
  26. filter:alpha(opacity=80);
  27. -moz-opacity:0.8;
  28. opacity:0.8;
  29. }
  30. </style>
  31. <scripttype="text/javascript"><!--
  32. varOz,Ov;
  33. varobj=[];
  34. varK=0;
  35. varimg,scr,W,H;
  36. varSP=40;/*speed*/
  37. vardz=false;
  38. /*htmlpositioning*/
  39. position=function(obj,x,y,w,h)
  40. {
  41. with(obj.style){
  42. left=Math.round(x)+"px";
  43. top=Math.round(y)+"px";
  44. width=Math.round(w)+"px";
  45. height=Math.round(h)+"px";
  46. }
  47. }
  48. /*createobjectinstances*/
  49. functionCobj(parent,N,x,y,w,h)
  50. {
  51. this.zoomed=(parent?0:1);
  52. obj[K]=this;
  53. this.K=K++;
  54. this.parent=parent;
  55. this.children=[];
  56. this.x=x;
  57. this.y=y;
  58. this.w=w;
  59. this.h=h;
  60. this.vx=0;
  61. this.vy=0;
  62. this.vw=0;
  63. this.vh=0;
  64. this.xi=0;
  65. this.yi=0;
  66. this.wi=0;
  67. this.hi=0;
  68. this.x1=0;
  69. this.y1=0;
  70. this.w1=0;
  71. this.h1=0;
  72. this.x0=0;
  73. this.y0=0;
  74. this.w0=0;
  75. this.h0=0;
  76. this.imgsrc=img[N];
  77. /*createHTMLelements*/
  78. this.img=document.createElement("img");
  79. thisthis.img.src=this.imgsrc.src;
  80. thisthis.img.obj=this;
  81. scr.appendChild(this.img);
  82. this.spa=document.createElement("span");
  83. this.spa.style.cursor="pointer";
  84. thisthis.spa.obj=this;
  85. scr.appendChild(this.spa);
  86. if(parent)parent.children.push(this);
  87. /*Flickr*/
  88. this.blink=function()
  89. {
  90. with(this)
  91. {
  92. position(spa,x0,y0,w0,h0);
  93. spa.style.visibility="visible";
  94. img.style.cursor="pointer";
  95. setTimeout("obj["+K+"].spa.style.visibility='hidden'",128);
  96. }
  97. }
  98. /*displayimage&children*/
  99. this.display=function(zoomed)
  100. {
  101. with(this)
  102. {
  103. position(img,x0,y0,w0,h0);
  104. img.style.visibility="visible";
  105. if(parent&&!zoomed)
  106. {
  107. blink();
  108. Ov=img;
  109. }
  110. }
  111. }
  112. /*initzoom*/
  113. this.init_zoom=function(d)
  114. {
  115. with(this)
  116. {
  117. w1=imgsrc.width;
  118. h1=imgsrc.height;
  119. x1=(W-w1)/2;
  120. y1=(H-h1)/2;
  121. x0=(parent?x+parent.x1:(W-w1)/2);
  122. y0=(parent?y+parent.y1:(H-h1)/2);
  123. w0=(parent?w:w1);
  124. h0=(parent?h:h1);
  125. xi=d>0?x0:x1;
  126. yi=d>0?y0:y1;
  127. wi=d>0?w0:w1;
  128. hi=d>0?h0:h1;
  129. vx=d*(x1-x0)/SP;
  130. vy=d*(y1-y0)/SP;
  131. vw=d*(w1-w0)/SP;
  132. vh=d*(h1-h0)/SP;
  133. parent.vx=d*((x1-(x*w1/w0))-parent.x1)/SP;
  134. parent.vy=d*((y1-(y*h1/h0))-parent.y1)/SP;
  135. parent.vw=vw*(parent?(parent.w1/w):0);
  136. parent.vh=vh*(parent?(parent.h1/h):0);
  137. }
  138. }
  139. /*animatezoomin-out*/
  140. this.zoom=function()
  141. {
  142. with(this)
  143. {
  144. xi+=vx;
  145. yi+=vy;
  146. wi+=vw;
  147. hi+=vh;
  148. parent.xi+=parent.vx;
  149. parent.yi+=parent.vy;
  150. parent.wi+=parent.vw;
  151. parent.hi+=parent.vh;
  152. position(img,xi,yi,wi,hi);
  153. position(parent.img,parent.xi,parent.yi,parent.wi,parent.hi);
  154. if((zoomed==0&&wi>w0-vw)||(zoomed==1&&wi<w1-vw))
  155. {
  156. setTimeout("obj["+K+"].zoom()",16);
  157. }
  158. else
  159. {
  160. dz=false;
  161. for(variinOz.children)
  162. {
  163. Oz.children[i].init_zoom();
  164. Oz.children[i].display(false,false);
  165. }
  166. }
  167. }
  168. }
  169. /*mouseevents*/
  170. this.img.onmouseover=function()
  171. {
  172. if(this!=Ov)with(this.obj)if(parent&&!zoomed&&!dz)blink();
  173. Ov=this;
  174. returnfalse;
  175. }
  176. this.img.onclick=function()
  177. {
  178. with(this.obj)
  179. {
  180. if(parent&&!dz&&imgsrc.complete)
  181. {
  182. if(zoomed==1)
  183. {
  184. /*zoomout*/
  185. Oz=this.obj.parent;
  186. zoomed=0;
  187. init_zoom(-1);
  188. for(variinchildren)children[i].img.style.visibility="hidden";
  189. parent.zoomed=1;
  190. dz=true;
  191. zoom();
  192. }
  193. elseif(zoomed==0)
  194. {
  195. /*zoomin*/
  196. Oz=this.obj;
  197. img.style.cursor="crosshair";
  198. zoomed=1;
  199. init_zoom(1);
  200. for(variinparent.children)
  201. {
  202. if(this.obj!=parent.children[i])
  203. parent.children[i].img.style.visibility="hidden";
  204. }
  205. parent.zoomed=-1;
  206. dz=true;
  207. zoom();
  208. }
  209. }
  210. }
  211. returnfalse;
  212. }
  213. this.spa.onmousedown=function()
  214. {
  215. this.style.visibility="hidden";
  216. this.obj.img.onclick();
  217. returnfalse;
  218. }
  219. }
  220. /*initialization*/
  221. /*muststartafterthefirstimageisloaded*/
  222. functionstarter()
  223. {
  224. scr=document.getElementById("screen");
  225. img=document.getElementById("images").getElementsByTagName("img");
  226. W=parseInt(scr.style.width);
  227. H=parseInt(scr.style.height);
  228. /*====tree-zoom====*/
  229. //newCobj(parent,image,x,y,w,h)
  230. O=newCobj(0,0,0,0,0,0);
  231. O0=newCobj(O,1,127,98,181,134);
  232. O1=newCobj(O0,2,158,150,85,155);
  233. O11=newCobj(O1,4,136,98,80,196);
  234. O111=newCobj(O11,5,20,154,70,57);
  235. O1111=newCobj(O111,6,161,137,154,76);
  236. O112=newCobj(O11,11,155,154,70,57);
  237. O1121=newCobj(O112,12,273,116,49,72);
  238. O2=newCobj(O0,3,281,150,90,154);
  239. O21=newCobj(O2,7,35,295,133,82);
  240. O211=newCobj(O21,15,316,183,20,36);
  241. O22=newCobj(O2,8,179,295,127,79);
  242. O221=newCobj(O22,13,132,84,54,102);
  243. O2211=newCobj(O221,14,6,234,69,50);
  244. O22111=newCobj(O2211,14,267,90,135,98);
  245. O23=newCobj(O2,9,92,148,138,76);
  246. O231=newCobj(O23,10,249,106,83,65);
  247. O2311=newCobj(O231,0,120,87,57,59);
  248. /*display*/
  249. O.init_zoom(1);
  250. O.display(true);
  251. for(variinO.children)
  252. {
  253. O.children[i].init_zoom(1);
  254. O.children[i].display(true);
  255. }
  256. }
  257. //-->
  258. </script>
  259. </head>
  260. <body>
  261. <divstyle="position:absolute;left:50%;top:50%">
  262. <divstyle="position:absolute;left:-220px;top:-170px;width:440px;height:340px;background:#000"></div>
  263. <divid="screen"style="position:absolute;left:-200px;top:-150px;width:400px;height:300px;overflow:hidden">
  264. </div>
  265. </div>
  266. <divid="images"style="position:absolute;left:-10000px;top:-10000px;">
  267. <imgonload="setTimeout('starter();',500)"src="wi37.jpg">
  268. <imgsrc="wi2.jpg">
  269. <imgsrc="wi7.jpg">
  270. <imgsrc="wi20.jpg">
  271. <imgsrc="wi3.jpg">
  272. <imgsrc="wi10.jpg">
  273. <imgsrc="wi30.jpg">
  274. <imgsrc="wi11.jpg">
  275. <imgsrc="wi21.jpg">
  276. <imgsrc="wi29.jpg">
  277. <imgsrc="wi19.jpg">
  278. <imgsrc="wi27.jpg">
  279. <imgsrc="wi33.jpg">
  280. <imgsrc="wi35.jpg">
  281. <imgsrc="wi42.jpg">
  282. <imgsrc="wi15.jpg">
  283. </div>
  284. </body>
  285. </html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值