user1878413
user1878413

Reputation: 1813

How to calc the proportional size of a image with Javascript/jQuery?

I have the width and the false height of a image and want calc a new proportional with Javascript/jQuery. Must use the width and calc the new height.

I hope anyone can help me.

Thanks!

Upvotes: 2

Views: 1401

Answers (2)

StaleMartyr
StaleMartyr

Reputation: 778

Im using css width:100% and using element.clientHeight to get its height.

Upvotes: 1

dane
dane

Reputation: 631

var newWidth = <whatever the new width is>;
var width = $('#imgID').width();
var proportion = newWidth/width;
var newHeight = <existing height> * proportion;

Upvotes: 4

Related Questions