Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Sorry for the sloppyness, kinda tired.</p> <p>If you use the code below, it does the same as my example above, except you can dynamically change the values of the <a href="http://jsfiddle.net/Sj7sK/2/" rel="nofollow">width and height through the textboxes</a>:</p> <p><strong>HTML</strong></p> <pre><code>&lt;div class="container"&gt; &lt;div&gt; &lt;input id="thumbWidth" placeholder="width" value="200" /&gt; &lt;input id="thumbHeight" placeholder="height" value="200" /&gt; &lt;/div&gt; &lt;p&gt; &lt;img id="ferret" src="http://odyniec.net/projects/imgareaselect/ferret.jpg" alt="It's coming right for us!" title="It's coming right for us!" style="float: left; margin-right: 10px;" /&gt; &lt;/p&gt; &lt;/div&gt; </code></pre> <p><strong>JAVASCRIPT</strong></p> <pre><code>$(document).ready(function () { var defaultVal = 100; var thumbWidth = $('#thumbWidth').val() | defaultVal, thumbHeight = $('#thumbHeight').val() | defaultVal; $('#thumbWidth').on("change keyup", function () { thumbWidth = this.value | defaultVal; reLoad('cancel'); }); $('#thumbHeight').on("change keyup", function () { thumbHeight = this.value | defaultVal; reLoad('cancel'); }); function preview(img, selection) { var scaleX = thumbWidth / (selection.width || 1); var scaleY = thumbHeight / (selection.height || 1); $('#ferret + div &gt; img').css({ width: Math.round(scaleX * $("#ferret").width()) + 'px', height: Math.round(scaleY * $("#ferret").height()) + 'px', marginLeft: '-' + Math.round(scaleX * selection.x1) + 'px', marginTop: '-' + Math.round(scaleY * selection.y1) + 'px' }); } var reLoad = function (cancel) { $('.premove').remove(); $('&lt;div class="premove"&gt;&lt;img src="http://odyniec.net/projects/imgareaselect/ferret.jpg" style="position: relative;" /&gt;&lt;div&gt;') .css({ float: 'left', position: 'relative', overflow: 'hidden', width: thumbWidth + 'px', height: thumbHeight + 'px' }) .insertAfter($('#ferret')); var fer = $('#ferret').imgAreaSelect({ aspectRatio: thumbWidth + ':' + thumbHeight, onSelectChange: preview, instance: true }); if (cancel) fer.cancelSelection(); } reLoad(); </code></pre> <p>});</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload