dynamically double image size
Posted
by
Edan Duarte
on Stack Overflow
See other posts from Stack Overflow
or by Edan Duarte
Published on 2012-06-04T04:36:13Z
Indexed on
2012/06/04
4:40 UTC
Read the original article
Hit count: 127
JavaScript
I have an embarrassingly simple question: How can I display an image at double its size without hard coding the width and height attributes? Here's what I tried, but I ended up having to just enter 1000 for width and height. Is something wrong with my function? Thanks!
<img onload="double(self.id);" name="bigPic" id="bigPic" src="album1.jpg" height="1000" width="1000"/>
function double(id) {
var img = document.getElementById(id);
var dblWdth = img.width * 2;
var dblHt = img.height * 2;
img.height = dblHt;
img.width = dblWdth;
}
© Stack Overflow or respective owner