开发者

Prototype Javascript: getting an elements width as an integer

开发者 https://www.devze.com 2023-04-10 18:04 出处:网络
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\".

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

精彩评论

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

关注公众号