flash2-2.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Document</title>
  6. <link rel="stylesheet" type="text/css" href="css/reset.css">
  7. <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
  8. <script type="text/javascript" src="js/hammer.min.js"></script>
  9. </head>
  10. <body>
  11. <div id="wrapper" class="wrapper">
  12. <div class="statue left"></div>
  13. <div class="statue right"></div>
  14. <div class="arrow"></div>
  15. <div class="mirror">
  16. <div class="mirror_content">
  17. <div class="front"><img src="images/buddha_front.png" alt=""></div>
  18. </div>
  19. </div>
  20. <div class="mirrow_down"></div>
  21. </div>
  22. <canvas id="myCanvas" width="794" height="612"></canvas>
  23. <style type="text/css" media="screen">
  24. @charset "UTF-8";
  25. html, body {
  26. font-size: 14px;
  27. font-family: '微軟正黑體',sans-serif;
  28. }
  29. body {
  30. overflow: hidden;
  31. }
  32. a {
  33. text-decoration: none;
  34. }
  35. * {
  36. box-sizing: border-box;
  37. }
  38. .arrow{
  39. width: 71px;
  40. height: 200px;
  41. background: url(images/arrow.png);
  42. position: absolute;
  43. left: 450px;
  44. top: 250px;
  45. }
  46. .wrapper {
  47. width: 794px;
  48. height: 612px;
  49. position: relative;
  50. }
  51. .wrapper .statue {
  52. width: 100px;
  53. height: 400px;
  54. background: url(images/buddha.png);
  55. position: absolute;
  56. right: 100px;
  57. bottom: 0;
  58. }
  59. .wrapper .statue.left {
  60. transform: scaleX(-1);
  61. left: 100px;
  62. right: auto;
  63. cursor: default;
  64. }
  65. .wrapper .mirror {
  66. width: 131px;
  67. height: 195px;
  68. background: url(images/mirrow_up.png);
  69. background-size: 100% 100%;
  70. position: absolute;
  71. left: 50%;
  72. margin-left: -65.5px;
  73. top: 20px;
  74. overflow: hidden;
  75. }
  76. .wrapper .mirror .mirror_content{
  77. width: 110px;
  78. height: 90%;
  79. position: absolute;
  80. left: 50%;
  81. margin-left: -55px;
  82. top: 5%;
  83. overflow: hidden;
  84. }
  85. .wrapper .mirrow_down {
  86. width: 9px;
  87. height: 195px;
  88. background: url(images/mirrow_down.png);
  89. background-size: 100% 100%;
  90. position: absolute;
  91. left: 50%;
  92. margin-left: -4.5px;
  93. top: 215px;
  94. cursor: pointer;
  95. }
  96. .wrapper .mirror .front {
  97. width: 100%;
  98. height: 200px;
  99. text-align: center;
  100. margin-top: 2px;
  101. }
  102. .wrapper .mirror .front img {
  103. height: 100%;
  104. width: auto;
  105. }
  106. #myCanvas {
  107. position: absolute;
  108. z-index: 10;
  109. left: 0;
  110. top: 0;
  111. pointer-events: none;
  112. }
  113. </style>
  114. <script type="text/javascript">
  115. var c = document.getElementById("myCanvas");
  116. var ctx = c.getContext("2d");
  117. var hammer = document.getElementById("wrapper");
  118. var mc = new Hammer(hammer);
  119. mc.get('pan').set({ direction: Hammer.DIRECTION_ALL });
  120. mc.on("panup pandown", function(ev) {
  121. var e = ev;
  122. e.pageY = ev.center.y;
  123. moveEvent(e);
  124. });
  125. mc.on("press", function(ev) {
  126. isPress = true;
  127. });
  128. mc.on("pressup", function(ev) {
  129. isPress = false;
  130. });
  131. var isPress = false;
  132. $(".mirrow_down").mousedown(function(e){
  133. isPress = true;
  134. });
  135. $(window).mouseup(function(){
  136. isPress = false;
  137. });
  138. $(".wrapper").mousemove(function(e){
  139. moveEvent(e);
  140. });
  141. function moveEvent(e){
  142. var mouseY = e.pageY;
  143. if (isPress && mouseY < 410 && mouseY > 320){
  144. if($('.arrow').length > 0) $('.arrow').remove();
  145. var height = mouseY - 215;
  146. $('.mirrow_down').css('height', height);
  147. $('.mirror').css({
  148. height: height,
  149. });
  150. var x1 = 400;
  151. var y1 = 225;
  152. var x2 = 400;
  153. var y2 = mouseY - 10;
  154. var statue = getPos($(".statue.left"));
  155. var statue2 = getPos($(".statue.right"));
  156. ctx.clearRect(0,0,794,612);
  157. ctx.strokeStyle = "#FF0000";
  158. ctx.beginPath();
  159. ctx.setLineDash([10,15]);
  160. ctx.moveTo(statue2.x + 20,statue2.y);
  161. ctx.lineTo(x1,y1);
  162. ctx.stroke();
  163. ctx.strokeStyle = "#0000FF";
  164. ctx.beginPath();
  165. ctx.moveTo(statue2.x + 20, height*2 + 150);
  166. ctx.lineTo(x2,y2);
  167. ctx.stroke();
  168. ctx.setLineDash([]);
  169. drawArrow(ctx, statue.x + 80, statue.y, x1, y1, 30, 20, 1.5, "#FF0000");
  170. drawArrow(ctx, x1, y1, statue.x + 80, statue.y + 50, 30, 20, 1.5, "#FF0000");
  171. drawArrow(ctx, x2, y2, statue.x + 80, statue.y + 50, 30, 20, 2, "#0000FF");
  172. drawArrow(ctx, statue.x + 80, height*2 + 150, x2, y2, 30, 20, 2, "#0000FF");
  173. ctx.strokeStyle = "#000000";
  174. ctx.lineWidth = 2;
  175. ctx.beginPath();
  176. ctx.moveTo(350, y1);
  177. ctx.lineTo(450, y1);
  178. ctx.moveTo(350, y2);
  179. ctx.lineTo(450, y2);
  180. ctx.stroke();
  181. ctx.closePath();
  182. }
  183. }
  184. function getPos(tar){
  185. var result = {};
  186. result.x = tar.offset().left;
  187. result.y = tar.offset().top;
  188. return result;
  189. }
  190. function drawArrow(ctx, fromX, fromY, toX, toY,theta,headlen,width,color) {
  191. theta = typeof(theta) != 'undefined' ? theta : 30;
  192. headlen = typeof(theta) != 'undefined' ? headlen : 10;
  193. width = typeof(width) != 'undefined' ? width : 1;
  194. color = typeof(color) != 'color' ? color : '#000';
  195. // 计算各角度和对应的P2,P3坐标
  196. var angle = Math.atan2(fromY - toY, fromX - toX) * 180 / Math.PI,
  197. angle1 = (angle + theta) * Math.PI / 180,
  198. angle2 = (angle - theta) * Math.PI / 180,
  199. topX = headlen * Math.cos(angle1),
  200. topY = headlen * Math.sin(angle1),
  201. botX = headlen * Math.cos(angle2),
  202. botY = headlen * Math.sin(angle2);
  203. ctx.save();
  204. ctx.beginPath();
  205. var arrowX = fromX - topX,
  206. arrowY = fromY - topY;
  207. ctx.moveTo(arrowX, arrowY);
  208. ctx.moveTo(fromX, fromY);
  209. ctx.lineTo(toX, toY);
  210. arrowX = toX + topX;
  211. arrowY = toY + topY;
  212. ctx.moveTo(arrowX, arrowY);
  213. ctx.lineTo(toX, toY);
  214. arrowX = toX + botX;
  215. arrowY = toY + botY;
  216. ctx.lineTo(arrowX, arrowY);
  217. ctx.strokeStyle = color;
  218. ctx.lineWidth = width;
  219. ctx.stroke();
  220. ctx.restore();
  221. }
  222. </script>
  223. </body>
  224. </html>