You can, but if you're using Javascript anyway you may as well just use it to make sure that the height of the image is kept proportional to its width.
Code:
functon Point(x, y) {
this.x = x;
this.y = y;
}
function Rectangle(tl, br) {
this.tl = tl;
this.br = br;
}
Rectangle.prototype = {
'width' : function() {
return this.br.x - this.tl.x;
},
'height' : function() {
return this.br.y - this.tl.y;
}
};
Rectangle.fromImage = function(imgurl) {
var im = new Image(imgurl);
return new Rectangle(new Point(0, 0), new Point(im.width, im.height));
};
Rectangle.fromElement = function(el) {
// Mostly from QuirksMode.
var curleft = 0,
curtop = 0,
oel = el;
if (el.offsetParent) {
curleft = el.offsetLeft;
curtop = el.offsetTop;
while(el = el.offsetParent) {
curleft += el.offsetLeft;
curtop += el.offsetTop;
}
}
return new Rectangle(new Point(curleft, curtop), new Point(curleft + oel.offsetWidth, curtop + oel.offsetHeight));
};
Bookmarks