flash2.html 4.8 KB

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