wepper wepper - 1 year ago 67
jQuery Question

Resize an image inside a container dynamically using jQuery

I have a div container, and I call it "content_container". This container is able to drag and resize using jQuery UI. Inside this container, I implemented TinyMCE (content text editor). My problem is:

If the user inserts a 2000 pixels x 2000 pixels image, the container max-width is 1000 pixels. Then it will look like this:

| Container header |
| text [image...................image]
| [image...................image]

(I am sorry, I am still developing it in my localhost, and I haven't found a web hosting company yet, thus I can't give you the direct link to see the demo).

Okay, the container is still resizeable, just that, the image size is always 2000 pixels x 2000 pixels. My question is: Is it possible when I resize the "content_container", the image will auto resize and fit into the container width?

If yes, how do I do it?

If no, is there another solution to solve this?


Before TinyMCE, the container code:

<div id="content_container">
<div id="header">The header</div>
<div id="content">
<div id="inlineEditor"></div>

After the user enters content (for example, insert the image), the container will become:

<div id="content_container">
<div id="header">The header</div>
<div id="content">
<div class="inlineEditor">
<p>some text <img alt="test" src="../usrXX/img/imgname.jpg"></p>

As you can see, I can only manipulate the inlineEditor class.

Answer Source

This answer is CSS based. Have you tried applying a class to your image like so?


And your image:

<img src="your_image.png" class="fluid-img">

Here's an example (tested in Chrome).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download