+ -
当前位置:首页 → 问答吧 → 牛人写的图片特效

牛人写的图片特效

时间:2010-07-06

来源:互联网


  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2. <html>
  3. <head>
  4. <title>Wanna tell her - interactive DHTML </title>
  5. <meta http-equiv="imagetoolbar" content="no">
  6. <style type="text/css">
  7. html {
  8. overflow: hidden;
  9. }
  10. body {
  11. position: absolute;
  12. margin: 0px;
  13. padding: 0px;
  14. background: #fff;
  15. width: 100%;
  16. height: 100%;
  17. }
  18. #screen {
  19. position: absolute;
  20. left: 10%;
  21. top: 10%;
  22. width: 80%;
  23. height: 80%;
  24. background: #fff;
  25. }
  26. #screen img {
  27. position: absolute;
  28. cursor: pointer;
  29. width: 0px;
  30. height: 0px;
  31. -ms-interpolation-mode:nearest-neighbor;
  32. }
  33. #bankImages {
  34. visibility: hidden;
  35. }
  36. #FPS {
  37. position: absolute;
  38. right: 5px;
  39. bottom: 5px;
  40. font-size: 10px;
  41. color: #666;
  42. font-family: verdana;
  43. }
  44. </style>
  45. <script type="text/javascript">
  46. /* ==== Easing function ==== */
  47. var Library = {};
  48. Library.ease = function () {
  49. this.target = 0;
  50. this.position = 0;
  51. this.move = function (target, speed) {
  52. this.position += (target - this.position) * speed;
  53. }
  54. }
  55. var tv = {
  56. /* ==== variables ==== */
  57. O : [],
  58. fps : 0,
  59. screen : {},
  60. angle : {
  61. x : new Library.ease(),
  62. y : new Library.ease()
  63. },
  64. camera : {
  65. x    : new Library.ease(),
  66. y    : new Library.ease()
  67. },
  68. create3DHTML : function (i, x, y, z, sw, sh) {
  69. /* ==== create HTML image element ==== */
  70. var o = document.createElement('img');
  71. o.src = i.src;
  72. tv.screen.obj.appendChild(o);
  73. /* ==== 3D coordinates ==== */
  74. o.point3D = {
  75. x  : x,
  76. y  : y,
  77. z  : new Library.ease(),
  78. sw : sw,
  79. sh : sh,
  80. w  : i.width,
  81. h  : i.height
  82. };
  83. o.point3D.z.target = z;
  84. /* ==== push object ==== */
  85. o.point2D = {};
  86. tv.O.push(o);
  87. /* ==== on mouse over event ==== */
  88. o.onmouseover = function () {
  89. if (this != tv.o) {
  90. this.point3D.z.target = tv.mouseZ;
  91. tv.camera.x.target = this.point3D.x;
  92. tv.camera.y.target = this.point3D.y;
  93. if (tv.o) tv.o.point3D.z.target = 0;
  94. tv.o = this;
  95. }
  96. return false;
  97. }
  98. /* ==== on mousedown event ==== */
  99. o.onmousedown = function () {
  100. if (this == tv.o) {
  101. if (this.point3D.z.target == tv.mouseZ) this.point3D.z.target = 0;
  102. else {
  103. tv.o = false;
  104. this.onmouseover();
  105. }
  106. }
  107. }
  108. /* ==== main 3D function ==== */
  109. o.animate = function () {
  110. /* ==== 3D coordinates ==== */
  111. var x = this.point3D.x - tv.camera.x.position;
  112. var y = this.point3D.y - tv.camera.y.position;
  113. this.point3D.z.move(this.point3D.z.target, this.point3D.z.target ? .15 : .08);
  114. /* ==== rotations ==== */
  115. var xy = tv.angle.cx * y  - tv.angle.sx * this.point3D.z.position;
  116. var xz = tv.angle.sx * y  + tv.angle.cx * this.point3D.z.position;
  117. var yz = tv.angle.cy * xz - tv.angle.sy * x;
  118. var yx = tv.angle.sy * xz + tv.angle.cy * x;
  119. /* ==== 2D transform ==== */
  120. var scale = tv.camera.focalLength / (tv.camera.focalLength + yz);
  121. x = yx * scale;
  122. y = xy * scale;
  123. var w = Math.round(Math.max(0, this.point3D.w * scale * this.point3D.sw));
  124. var h = Math.round(Math.max(0, this.point3D.h * scale * this.point3D.sh));
  125. /* ==== HTML rendering ==== */
  126. var o    = this.style;
  127. o.left  = Math.round(x + tv.screen.w - w * .5) + 'px';
  128. o.top    = Math.round(y + tv.screen.h - h * .5) + 'px';
  129. o.width  = w + 'px';
  130. o.height = h + 'px';
  131. o.zIndex = 10000 + Math.round(scale * 1000);
  132. }
  133. },
  134. /* ==== init script ==== */
  135. init : function (structure, FL, mouseZ, rx, ry) {
  136. this.screen.obj = document.getElementById('screen');
  137. this.screen.obj.onselectstart = function () { return false; }
  138. this.screen.obj.ondrag        = function () { return false; }
  139. this.mouseZ = mouseZ;
  140. this.camera.focalLength = FL;
  141. this.angle.rx = rx;
  142. this.angle.ry = ry;
  143. /* ==== create objects ==== */
  144. var i = 0, o;
  145. while( o = structure[i++] )
  146. this.create3DHTML(o.img, o.x, o.y, o.z, o.sw, o.sh);
  147. /* ==== start script ==== */
  148. this.resize();
  149. mouse.y = this.screen.y + this.screen.h;
  150. mouse.x = this.screen.x + this.screen.w;
  151. /* ==== loop ==== */
  152. setInterval(tv.run, 16);
  153. setInterval(tv.dFPS, 1000);
  154. },
  155. /* ==== resize window ==== */
  156. resize : function () {
  157. var o = tv.screen.obj;
  158. if (o) {
  159. tv.screen.w = o.offsetWidth / 2;
  160. tv.screen.h = o.offsetHeight / 2;
  161. for (tv.screen.x = 0, tv.screen.y = 0; o != null; o = o.offsetParent) {
  162. tv.screen.x += o.offsetLeft;
  163. tv.screen.y += o.offsetTop;
  164. }
  165. }
  166. },
  167. /* ==== main loop ==== */
  168. run : function () {
  169. tv.fps++;
  170. /* ==== motion ease ==== */
  171. tv.angle.x.move(-(mouse.y - tv.screen.h - tv.screen.y) * tv.angle.rx, .1);
  172. tv.angle.y.move( (mouse.x - tv.screen.w - tv.screen.x) * tv.angle.ry, .1);
  173. tv.camera.x.move(tv.camera.x.target, .025);
  174. tv.camera.y.move(tv.camera.y.target, .025);
  175. /* ==== angles sin and cos ==== */
  176. tv.angle.cx = Math.cos(tv.angle.x.position);
  177. tv.angle.sx = Math.sin(tv.angle.x.position);
  178. tv.angle.cy = Math.cos(tv.angle.y.position);
  179. tv.angle.sy = Math.sin(tv.angle.y.position);
  180. /* ==== loop through images ==== */
  181. var i = 0, o;
  182. while( o = tv.O[i++] ) o.animate();
  183. },
  184. /* ==== trace frames per seconds ==== */
  185. dFPS : function () {
  186. document.getElementById('FPS').innerHTML = tv.fps + ' FPS';
  187. tv.fps = 0;
  188. }
  189. }
  190. /* ==== global mouse position ==== */
  191. var mouse = {
  192. x : 0,
  193. y : 0
  194. }
  195. document.onmousemove = function(e) {
  196. if (window.event) e = window.event;
  197. mouse.x = e.clientX;
  198. mouse.y = e.clientY;
  199. return false;
  200. }
  201. /* ==== starting script ==== */
  202. onload = function() {
  203. onresize = tv.resize;
  204. /* ==== build grid ==== */
  205. var img = document.getElementById('bankImages').getElementsByTagName('img');
  206. var structure = [];
  207. for (var i = -300; i <= 300; i += 120)
  208. for (var j = -300; j <= 300; j += 120)
  209. structure.push({ img:img[0], x:i, y:j, z:0, sw:.5, sh:.5 });
  210. /* ==== let's go ==== */
  211. tv.init(structure, 350, -200, .005, .0025);
  212. }
  213. </script>
  214. </head>
  215. <body>
  216. <div id="screen"> </div>
  217. <div id="bankImages">
  218. <img alt="" src="http://avatar.profile.csdn.net/D/0/9/2_cicadu.jpg">
  219. </div>
  220. <div id="FPS"> </div>
  221. </body>
  222. </html>
复制代码

作者: lusuli2010   发布时间: 2010-07-06

崇拜中....

作者: lusuli2010   发布时间: 2010-07-06

崇拜中....
lusuli2010 发表于 2010-7-6 10:40

作者: seyou568   发布时间: 2010-07-06

传送门:http://bbs.phpchina.com/viewthre ... ghlight=%2Byoursjzz

作者: tigerjazz   发布时间: 2010-07-06

回复 tigerjazz


    我是在网上找的,没有传送你什么什么的,.你要是真有本事,你把这段代码给注释给我们看看...

作者: lusuli2010   发布时间: 2010-07-06

效果太棒了!顶一个

作者: linzg3   发布时间: 2010-07-07

前台太熟练了,佩服。

作者: qixiaodui   发布时间: 2010-07-25

作者: zzt05   发布时间: 2010-07-25

相关阅读 更多