Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ Options
<td>targetHeight</td><td>integer</td><td>180</td><td>no</td>
<td>Height in pixels of the cropping window</td>
</tr>
<tr>
<td>startX</td><td>integer</td><td>null</td><td>no</td>
<td>Set start image position on X axis.</td>
</tr>
<tr>
<td>startY</td><td>integer</td><td>null</td><td>no</td>
<td>Set start image position on Y axis.</td>
</tr>
<tr>
<td>onChange</td><td>function</td><td>function(){}</td><td>no</td>
<td>Callback function that gets called whenever the values change. cropX, cropY, cropW, cropH, mustStretch (boolean) values are passed to this function in a hash. Use the this keyword in the function for a reference to the element that was updated.</td>
Expand Down
13 changes: 10 additions & 3 deletions jquery.jWindowCrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@
base.setZoom(base.workingPercent-zoomIncrement);
return false;
};
base.setFocus = function (x, y) {
base.$image.css({'left' : (x*-1*base.workingPercent.toString()+'px'), 'top' : (y*-1*base.workingPercent.toString()+'px')});
};

function initializeDimensions() {
if(base.originalWidth == 0) {
Expand All @@ -108,9 +111,13 @@
base.focalPoint = {'x': Math.round(x), 'y': Math.round(y)};
}
function focusOnCenter() {
var left = fillContainer((Math.round((base.focalPoint.x*base.workingPercent) - base.options.targetWidth/2)*-1), base.$image.width(), base.options.targetWidth);
var top = fillContainer((Math.round((base.focalPoint.y*base.workingPercent) - base.options.targetHeight/2)*-1), base.$image.height(), base.options.targetHeight);
base.$image.css({'left': (left.toString()+'px'), 'top': (top.toString()+'px')})
if ( typeof base.options.startX != null && typeof base.options.startY != null ) {
base.setFocus( base.options.startX, base.options.startY );
} else {
var left = fillContainer((Math.round((base.focalPoint.x*base.workingPercent) - base.options.targetWidth/2)*-1), base.$image.width(), base.options.targetWidth);
var top = fillContainer((Math.round((base.focalPoint.y*base.workingPercent) - base.options.targetHeight/2)*-1), base.$image.height(), base.options.targetHeight);
base.$image.css({'left': (left.toString()+'px'), 'top': (top.toString()+'px')});
}
storeFocalPoint();
}
function updateResult() {
Expand Down