tutorial3.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>Aspect Ratio with Preview Pane | Jcrop Demo</title>
  5. <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
  6. <script src="../js/jquery.min.js"></script>
  7. <script src="../js/jquery.Jcrop.js"></script>
  8. <script type="text/javascript">
  9. jQuery(function($){
  10. // Create variables (in this scope) to hold the API and image size
  11. var jcrop_api,
  12. boundx,
  13. boundy,
  14. // Grab some information about the preview pane
  15. $preview = $('#preview-pane'),
  16. $pcnt = $('#preview-pane .preview-container'),
  17. $pimg = $('#preview-pane .preview-container img'),
  18. xsize = $pcnt.width(),
  19. ysize = $pcnt.height();
  20. console.log('init',[xsize,ysize]);
  21. $('#target').Jcrop({
  22. onChange: updatePreview,
  23. onSelect: updatePreview,
  24. aspectRatio: xsize / ysize
  25. },function(){
  26. // Use the API to get the real image size
  27. var bounds = this.getBounds();
  28. boundx = bounds[0];
  29. boundy = bounds[1];
  30. // Store the API in the jcrop_api variable
  31. jcrop_api = this;
  32. // Move the preview into the jcrop container for css positioning
  33. $preview.appendTo(jcrop_api.ui.holder);
  34. });
  35. function updatePreview(c)
  36. {
  37. if (parseInt(c.w) > 0)
  38. {
  39. var rx = xsize / c.w;
  40. var ry = ysize / c.h;
  41. $pimg.css({
  42. width: Math.round(rx * boundx) + 'px',
  43. height: Math.round(ry * boundy) + 'px',
  44. marginLeft: '-' + Math.round(rx * c.x) + 'px',
  45. marginTop: '-' + Math.round(ry * c.y) + 'px'
  46. });
  47. }
  48. };
  49. });
  50. </script>
  51. <link rel="stylesheet" href="demo_files/main.css" type="text/css" />
  52. <link rel="stylesheet" href="demo_files/demos.css" type="text/css" />
  53. <link rel="stylesheet" href="../css/jquery.Jcrop.css" type="text/css" />
  54. <style type="text/css">
  55. /* Apply these styles only when #preview-pane has
  56. been placed within the Jcrop widget */
  57. .jcrop-holder #preview-pane {
  58. display: block;
  59. position: absolute;
  60. z-index: 2000;
  61. top: 10px;
  62. right: -280px;
  63. padding: 6px;
  64. border: 1px rgba(0,0,0,.4) solid;
  65. background-color: white;
  66. -webkit-border-radius: 6px;
  67. -moz-border-radius: 6px;
  68. border-radius: 6px;
  69. -webkit-box-shadow: 1px 1px 5px 2px rgba(0, 0, 0, 0.2);
  70. -moz-box-shadow: 1px 1px 5px 2px rgba(0, 0, 0, 0.2);
  71. box-shadow: 1px 1px 5px 2px rgba(0, 0, 0, 0.2);
  72. }
  73. /* The Javascript code will set the aspect ratio of the crop
  74. area based on the size of the thumbnail preview,
  75. specified here */
  76. #preview-pane .preview-container {
  77. width: 250px;
  78. height: 170px;
  79. overflow: hidden;
  80. }
  81. </style>
  82. </head>
  83. <body>
  84. <div class="container">
  85. <div class="row">
  86. <div class="span12">
  87. <div class="jc-demo-box">
  88. <div class="page-header">
  89. <ul class="breadcrumb first">
  90. <li><a href="../index.html">Jcrop</a> <span class="divider">/</span></li>
  91. <li><a href="../index.html">Demos</a> <span class="divider">/</span></li>
  92. <li class="active">Aspect Ratio with Preview Pane</li>
  93. </ul>
  94. <h1>Aspect Ratio with Preview Pane</h1>
  95. </div>
  96. <img src="demo_files/sago.jpg" id="target" alt="[Jcrop Example]" />
  97. <div id="preview-pane">
  98. <div class="preview-container">
  99. <img src="demo_files/sago.jpg" class="jcrop-preview" alt="Preview" />
  100. </div>
  101. </div>
  102. <div class="description">
  103. <p>
  104. <b>An example implementing a preview pane.</b>
  105. Obviously the most visual demo, the preview pane is accomplished
  106. entirely outside of Jcrop with a simple jQuery-flavored callback.
  107. This type of interface could be useful for creating a thumbnail
  108. or avatar. The onChange event handler is used to update the
  109. view in the preview pane.
  110. </p>
  111. </div>
  112. <div class="tapmodo-footer">
  113. <a href="http://tapmodo.com" class="tapmodo-logo segment">tapmodo.com</a>
  114. <div class="segment"><b>&copy; 2008-2013 Tapmodo Interactive LLC</b><br />
  115. Jcrop is free software released under <a href="../MIT-LICENSE.txt">MIT License</a>
  116. </div>
  117. </div>
  118. <div class="clearfix"></div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </body>
  124. </html>