user3819989
user3819989

Reputation: 1

how to resize div when browser resize using javascript

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.

Upvotes: 0

Views: 95

Answers (1)

Rishabh Shah
Rishabh Shah

Reputation: 679

Try this:

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

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

Upvotes: 1

Related Questions