odyniec / imgareaselect

ImgAreaSelect is a jQuery plugin for selecting a rectangular area of an image. It allows web developers to easily implement image cropping functionality, as well as other user interface features, such as photo notes (like those on Flickr).
http://odyniec.net/projects/imgareaselect/
686 stars 197 forks source link

Wrong position in bootstrap modal #57

Open paradisehuman opened 10 years ago

paradisehuman commented 10 years ago

Hi. I set parent in initializing imgAreaSelect to prevent scroll moving area :

thumb.imgAreaSelect({ handles: true, aspectRatio: '1:1', fadeSpeed: 300, parent: "#thumbBox" }) and this is my html :

paradisehuman commented 10 years ago

I solved this My self... Refer to this link : Fix #39

We must remove these lines from code :

/* Also check if any of the ancestor elements has fixed position */ if ($p.css('position') == 'fixed') position = 'fixed'; And we must position relative the parent box that we initialized ourselves( parent: "#thumbBox").

acechase commented 9 years ago

FWIW, I needed to make an additional change (in addition to removing position="fixed") for this to work in my bootstrap v3.0 modal.

If I passed in the parent then the offsets were being based off the body rather than off the modal container. Passing in the img.offsetParent as the parent element almost fixed it since the offsets were then correct, but the elements were then appended at the wrong place in the DOM.

The way I eventually got it working was passing in img.parent() as my parent, but then in the adjust() function I needed to use the img's offsetParent rather than parent to get the correct offsets. My diff looks like:

+++ b/EatWith/static/lib/jquery.imgareaselect/jquery.imgareaselect-0.9.10.js
@@ -146,9 +146,10 @@ $.imgAreaSelect = function (img, options) {
             imgOfs.left += max(document.body.scrollLeft, docElem.scrollLeft);
         }

-        parOfs = /absolute|relative/.test($parent.css('position')) ?
-            { left: round($parent.offset().left) - $parent.scrollLeft(),
-                top: round($parent.offset().top) - $parent.scrollTop() } :
+        var offsetParent = $parent.offsetParent();
+        parOfs = /absolute|relative/.test(offsetParent.css('position')) ?
+            { left: round(offsetParent.offset().left) - offsetParent.scrollLeft(),
+                top: round(offsetParent.offset().top) - offsetParent.scrollTop() } :