index3.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>jquery.iviewer test</title>
  6. <script type="text/javascript" src="jquery.js" ></script>
  7. <script type="text/javascript" src="jqueryui.js" ></script>
  8. <script type="text/javascript" src="jquery.mousewheel.min.js" ></script>
  9. <script type="text/javascript" src="../jquery.iviewer.js" ></script>
  10. <script type="text/javascript">
  11. jQuery(function($){
  12. var viewer;
  13. function isInCircle(x, y) {
  14. var relative_x = x - this.x;
  15. var relative_y = y - this.y;
  16. return Math.sqrt(relative_x*relative_x + relative_y*relative_y) <= this.r;
  17. }
  18. function isInRectangle(x, y) {
  19. return (this.x1 <= x && x <= this.x2) && (this.y1 <= y && y<= this.y2);
  20. }
  21. function getCircleCenter() { return {x: this.x, y: this.y}; }
  22. function getRectangleCenter() { return {x: (this.x2+this.x1)/2, y: (this.y2+this.y1)/2}; }
  23. var objects = [
  24. {x: 100, y: 100, r: 50, isInObject: isInCircle, title: 'big circle', getCenter: getCircleCenter },
  25. {x: 150, y: 250, r: 35, isInObject: isInCircle, title: 'middle circle', getCenter: getCircleCenter },
  26. {x: 500, y: 300, r: 10, isInObject: isInCircle, title: 'small circle', getCenter: getCircleCenter },
  27. {x1: 200, y1: 400, x2: 300, y2: 500, isInObject: isInRectangle, title: 'rectangle', getCenter: getRectangleCenter }
  28. ]
  29. function whereIam(x, y) {
  30. for (var i=0; i<objects.length; i++) {
  31. var obj = objects[i];
  32. if (obj.isInObject(x, y))
  33. return obj;
  34. }
  35. return null;
  36. }
  37. function showMe(ev, a) {
  38. $.each(objects, function(i, object) {
  39. if (object.title == $(a).html()) {
  40. var center = object.getCenter();
  41. var offset = viewer.iviewer('imageToContainer', center.x, center.y);
  42. var containerOffset = viewer.iviewer('getContainerOffset');
  43. var pointer = $('#pointer');
  44. offset.x += containerOffset.left - 20;
  45. offset.y += containerOffset.top - 40;
  46. pointer.css('display', 'block');
  47. pointer.css('left', offset.x+'px');
  48. pointer.css('top', offset.y+'px');
  49. }
  50. });
  51. ev.preventDefault();
  52. }
  53. window.showMe = showMe;
  54. viewer = $("#viewer1").iviewer({
  55. src: "test_active_with_objects.GIF",
  56. onClick: function(ev, coords) {
  57. var object = whereIam(coords.x, coords.y);
  58. if (object)
  59. alert('Clicked at ('+coords.x+', '+coords.y+'). This is '+object.title);
  60. },
  61. onMouseMove: function(ev, coords) {
  62. var object = whereIam(coords.x, coords.y);
  63. if (object) {
  64. $('#status').html('You are in ('+coords.x.toFixed(1)+', '+coords.y.toFixed(1)+'). This is '+object.title);
  65. this.container.css('cursor', 'crosshair');
  66. } else {
  67. $('#status').html('You are in ('+coords.x.toFixed(1)+', '+coords.y.toFixed(1)+'). This is empty space');
  68. this.container.css('cursor', null);
  69. }
  70. },
  71. onBeforeDrag: function(ev, coords) {
  72. // remove pointer if image is getting moving
  73. // because it's not actual anymore
  74. $('#pointer').css('display', 'none');
  75. // forbid dragging when cursor is whithin the object
  76. return whereIam(coords.x, coords.y) ? false : true;
  77. },
  78. onZoom: function(ev) {
  79. // remove pointer if image is resizing
  80. // because it's not actual anymore
  81. $('#pointer').css('display', 'none');
  82. },
  83. initCallback: function(ev) {
  84. this.container.context.iviewer = this;
  85. }
  86. });
  87. });
  88. </script>
  89. <link rel="stylesheet" href="../jquery.iviewer.css" />
  90. <style>
  91. html, body {
  92. height: 100%;
  93. padding: 0;
  94. margin: 0;
  95. }
  96. .viewer
  97. {
  98. height: 100%;
  99. position: relative;
  100. background-color: lightgreen;
  101. }
  102. .wrapper
  103. {
  104. border: 1px solid black;
  105. position: absolute;
  106. top: 5em;
  107. left: 1em;
  108. bottom: 1em;
  109. right: 1em;
  110. overflow: hidden; /*for opera*/
  111. }
  112. .toolbar
  113. {
  114. border: 1px solid black;
  115. position: absolute;
  116. top: 1em;
  117. left: 1em;
  118. right: 1em;
  119. height: 3em;
  120. }
  121. #pointer
  122. {
  123. background-image: url('arrow.png');
  124. width: 40px;
  125. height: 40px;
  126. position: absolute;
  127. display: none;
  128. }
  129. </style>
  130. </head>
  131. <body>
  132. <div class="toolbar">
  133. <span id="status"></span>|Show me:
  134. <a href="#" onclick="showMe(event, this)">big circle</a>,
  135. <a href="#" onclick="showMe(event, this)">middle circle</a>,
  136. <a href="#" onclick="showMe(event, this)">small circle</a>,
  137. <a href="#" onclick="showMe(event, this)">rectangle</a>
  138. </div>
  139. <div class="wrapper">
  140. <div id="viewer1" class="viewer"></div>
  141. </div>
  142. <div id="pointer"></div>
  143. </body>
  144. </html>