circle.html 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Circles | Jcrop Demos</title>
  5. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  6. <script src="../js/Jcrop.js"></script>
  7. <script type="text/javascript">
  8. var cb, filter;
  9. jQuery(function($){
  10. // Create a new Selection object extended from Selection
  11. var CircleSel = function(){ };
  12. // Set the custom selection's prototype object to be an instance
  13. // of the built-in Selection object
  14. CircleSel.prototype = new $.Jcrop.component.Selection();
  15. // Then we can continue extending it
  16. $.extend(CircleSel.prototype,{
  17. zoomscale: 1,
  18. attach: function(){
  19. this.frame.css({
  20. background: 'url(' + $('#target')[0].src.replace('750','750') + ')'
  21. });
  22. },
  23. positionBg: function(b){
  24. var midx = ( b.x + b.x2 ) / 2;
  25. var midy = ( b.y + b.y2 ) / 2;
  26. var ox = (-midx*this.zoomscale)+(b.w/2);
  27. var oy = (-midy*this.zoomscale)+(b.h/2);
  28. //this.frame.css({ backgroundPosition: ox+'px '+oy+'px' });
  29. this.frame.css({ backgroundPosition: -(b.x+1)+'px '+(-b.y-1)+'px' });
  30. },
  31. redraw: function(b){
  32. // Call original update() method first, with arguments
  33. $.Jcrop.component.Selection.prototype.redraw.call(this,b);
  34. this.positionBg(this.last);
  35. return this;
  36. },
  37. prototype: $.Jcrop.component.Selection.prototype
  38. });
  39. // Jcrop Initialization
  40. $('#target').Jcrop({
  41. // Change default Selection component for new selections
  42. selectionComponent: CircleSel,
  43. // Use a default filter chain that omits shader
  44. applyFilters: [ 'constrain', 'extent', 'backoff', 'ratio', 'round' ],
  45. // Start with circles only
  46. aspectRatio: 1,
  47. // Set an initial selection
  48. setSelect: [ 147, 55, 456, 390 ],
  49. // Only n/s/e/w handles
  50. handles: [ 'n','s','e','w' ],
  51. // No dragbars or borders
  52. dragbars: [ ],
  53. borders: [ ]
  54. },function(){
  55. this.container.addClass('jcrop-circle-demo');
  56. interface_load(this);
  57. });
  58. function interface_load(obj){
  59. cb = obj;
  60. // Add in a custom shading element...
  61. cb.container.prepend($('<div />').addClass('custom-shade'));
  62. function random_coords() {
  63. return [
  64. Math.random()*300,
  65. Math.random()*200,
  66. (Math.random()*540)+50,
  67. (Math.random()*340)+60
  68. ];
  69. }
  70. // Settings Buttons
  71. $(document.body).on('click','[data-setting]',function(e){
  72. var $targ = $(e.target),
  73. setting = $targ.data('setting'),
  74. value = $targ.data('value'),
  75. opt = {};
  76. opt[setting] = value;
  77. cb.setOptions(opt);
  78. $targ.closest('.btn-group').find('.active').removeClass('active');
  79. $targ.addClass('active');
  80. if ((setting == 'multi') && !value) {
  81. var m = cb.ui.multi, s = cb.ui.selection;
  82. for(var i=0;i<m.length;i++)
  83. if (s !== m[i]) m[i].remove();
  84. cb.ui.multi = [ s ];
  85. s.focus();
  86. }
  87. e.preventDefault();
  88. });
  89. // Animate button event
  90. $(document.body).on('click','[data-action]',function(e){
  91. var $targ = $(e.target);
  92. var action = $targ.data('action');
  93. switch(action){
  94. case 'random-move':
  95. cb.ui.selection.animateTo(random_coords());
  96. break;
  97. }
  98. cb.ui.selection.refresh();
  99. }).on('selectstart',function(e){
  100. e.preventDefault();
  101. }).on('click','a[data-action]',function(e){
  102. e.preventDefault();
  103. });
  104. }
  105. });
  106. </script>
  107. <link rel="stylesheet" href="demo_files/main.css">
  108. <link rel="stylesheet" href="demo_files/demos.css">
  109. <link rel="stylesheet" href="../css/Jcrop.css"><style type="text/css">.jcrop-circle-demo .jcrop-box {
  110. position: absolute;
  111. top: 0px;
  112. left: 0px;
  113. width: 100%;
  114. height: 100%;
  115. border: 1px rgba(255, 255, 255, 0.4) solid;
  116. border-radius: 50%;
  117. -webkit-box-shadow: 1px 1px 26px #000000;
  118. -moz-box-shadow: 1px 1px 26px #000000;
  119. box-shadow: 1px 1px 26px #000000;
  120. overflow: hidden;
  121. }
  122. .jcrop-circle-demo .jcrop-box:focus {
  123. outline: none;
  124. }
  125. .custom-shade {
  126. position: absolute;
  127. top: 0px;
  128. left: 0px;
  129. background-color: black;
  130. opacity: 0.4;
  131. width: 100%;
  132. height: 100%;
  133. }
  134. </style>
  135. </head>
  136. <body>
  137. <div class="navbar navbar-fixed-top">
  138. <div class="navbar-inner">
  139. <div class="container">
  140. <button type="button" data-toggle="collapse" data-target="nav-collapse" class="btn btn-navbar"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></button><a href="../" class="brand">Jcrop</a>
  141. <div class="nav-collapse collapse">
  142. <ul class="nav">
  143. <li class="active"><a href="./basic.html">Demos</a>
  144. </li>
  145. <li><a href="http://beta.jcrop.org/doc/">Docs</a>
  146. </li>
  147. <li><a href="http://beta.jcrop.org/contact/">Contact</a>
  148. </li>
  149. </ul>
  150. </div>
  151. </div>
  152. </div>
  153. </div>
  154. <div class="container">
  155. <div class="row">
  156. <div class="span12">
  157. <div class="jc-demo-box">
  158. <div class="page-header">
  159. <h1>Circles</h1>
  160. </div>
  161. <div class="demo-nav menu-box">
  162. <h3>Jcrop Demos</h3>
  163. <ul class="links">
  164. <li><a href="basic.html">Hello World</a></li>
  165. <li><a href="thumbnail.html">Thumbnail Preview</a></li>
  166. <li><a href="panel.html">Feature Panel</a></li>
  167. <li><a href="coords.html">Dimensions</a></li>
  168. <li><b>Circles</b></li>
  169. </ul>
  170. </div>
  171. <div class="page-interface"><img src="http://jcrop-cdn.tapmodo.com/assets/images/sierra2-750.jpg" id="target">
  172. <div class="btn-toolbar"><a href="#" data-action="random-move" id="moveselection" class="btn btn-small">Move</a><span class="btn-group"><a href="#" data-setting="aspectRatio" data-value="1" class="btn active btn-small">Circle</a><a href="#" data-setting="aspectRatio" data-value="0" class="btn btn-small">Ellipse</a></span><span class="btn-group"><a href="#" data-setting="multi" data-value="0" class="btn active btn-small">Single </a><a href="#" data-setting="multi" data-value="1" class="btn btn-small">Multi</a></span></div>
  173. <h3>About This Demo</h3><p><strong>And you thought Jcrop could only do rectangles!</strong> Well, that&#39;s still
  174. mostly true. This demo implements a custom <code>Selection</code> object that
  175. uses CSS properties to create the appearance of circles and ellipses.</p>
  176. <h4>Custom CSS and Shading</h4>
  177. <p>By setting the CSS property <code>border-radius: 50%</code>, we can give the
  178. selection an appearance of a circle or an ellipse. The built-in
  179. shader filter has been disabled, and a semi-opaque <code>&lt;div&gt;</code> has been
  180. inserted over the image to give the appearance of shading.</p>
  181. <h4>Cropping Irregular Selections</h4>
  182. <p>If you actually want to <em>crop</em> a circle or an ellipse, you&#39;re on
  183. your own. Jcrop will provide the rectangular coordinates for these
  184. crops, and further processing can be done to extract the circle
  185. or ellipse from the image.</p>
  186. </div>
  187. <div class="tapmodo-footer"><a href="http://tapmodo.com" class="tapmodo-logo segment">tapmodo.com</a>
  188. <div class="segment"><b>&copy; 2008-2013 Tapmodo Interactive LLC</b>
  189. <div>Jcrop is free software released under <a href="../MIT-LICENSE.txt">MIT License</a></div>
  190. </div>
  191. </div>
  192. <div class="clearfix"></div>
  193. </div>
  194. </div>
  195. </div>
  196. </div>
  197. </body>
  198. </html>