开发者

Prototype Javascript: getting an elements width as an integer

for mobile version of my site, I need to change the size of my icons.

This way I give those Icons that are too small the class "icon".

Then I iterate all img.icon's and want to change their size:

$$("img.icon").each(function (e) {
  // what to do now? e.setStyle({width: (e.width * 2).toString() + "px"});
});

How do I get the width and heigh开发者_如何学编程t of an image in pixels as an integer?

Thanks, yours Joern.


Try this:

e.setStyle({width: (e.getDimensions().width * 2).toString() + "px"});

Also, like @clockworkgeek said, make sure to place the above code in a function that waits for the DOM to be loaded, and the image as well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜