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