0

Is it possible to resize the entire 'div' container using javascript ? Inside my div i have 2 images and placed one over another. 1st image has is 720x1280 and 2nd image has 40x40. Now, while resizing my div container both the images should get resized proposinally.

function addWidth() {
var elem = document.getElementById("Image1");
if (elem != null) {
var mydiv = elem.clientWidth;
document.getElementById("divImage").style.width = mydiv + "px";
}
}
function resizediv() {
var height = window.innerWidth;
if (document.body.clientHeight) {
height = document.body.clientHeight;
}
height = parseInt(height) - 10;
document.getElementById("Image1").style.height = parseInt(height - document.getElementById("divImage").offsetTop - 8) + "px";
}
window.onresize = resizediv;

I have tried for an single image and its works fine. But i want the same to happens for an div container.

2
  • 1
    Could you not just add max-width: 100% to the images in CSS? Commented Jul 9, 2014 at 10:59
  • I think this can be solved in css... Commented Jul 9, 2014 at 11:00

1 Answer 1

1

Try this:

$(window).resize(function() {
    addWidth();
    resizediv();
});

Along with this, like @Alex said, you can also add width:100% for the images.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks for your reply. Is it possible to resize the entire 'div' container using javascript ? Inside my div i have 2 images and placed one over another. 1st image has 720x1280 and 2nd image has 40x40. Now, while resizing my div container both the images should get resized proposinally.
i dont have any idea to do. I just tried "fit to screen" with an single image. it works fine. Attached above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.