~ overflow ~

Tag: jcrop

Dynamic width / height jQuery tools overlay content

by z3n on Jun.17, 2010, under Coding, Tips & Hints

Problem:

I have a form where user sends a image and, if needed, he will select an area of the image for cropping. Everything is loaded by AJAX and image size is dynamic, nothing wrong with Jcrop but overlay is not able to work right if there’s no width set the div floats at wrong position.

The setup of the form is quite complex (uploadify + jQuery tools overlay + Jcrop + AJAX), so it was complicated isolating the issue.

Solution:

By adding a image height / width reply to the ajax after image upload, setting the overlay container css width with it and reloading the overlay call fixed the issue.
Here’s a snippet:

				$("#crop_container").css({
					height:"auto",
					width: r.w+"px"
				}).overlay({
					speed: 500,
					fixed:false,
					closeOnClick: false,
					closeOnEsc: false,
					oneInstance: true,
					mask: {
						color: '#fff',
						opacity: 0.5
					}
				});

				$("#crop_container > span").html("<img height="+r.h+" width="+r.w+" src='"+img+"?"+Math.random()+"' id='crop_img'>");
1 Comment :, , , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!