在IE中缩放图像 [英] Scaling images in IE

查看:71
本文介绍了在IE中缩放图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IE中遇到了非常奇怪的行为,不确定如何绕过它。


我正试图通过指定一个高度来缩放图像s小于

图像的实际高度,如下所示:


var myImg = document.createElement(" img");

myImg.src =" foo.jpg";

myImg.style.height =" 100px";


在Firefox中,这是正确的:图像自动缩放

从200 x 200到100 x 100.但在IE中,我最终得到的图像是200 x

100.高度改变,但宽度保持不变。


这种行为似乎取决于图像是在缓存中还是

没有。


有谁知道如何解决这个问题?


谢谢!

I''m getting really strange behavior in IE, not sure how to get around it.

I''m trying to scale an image by specifying a height that''s less than the
image''s actual height, like this:

var myImg = document.createElement("img");
myImg.src = "foo.jpg";
myImg.style.height = "100px";

In Firefox, this does the right thing: the image is automatically scaled
from 200 x 200 to 100 x 100. But in IE, I end up with an image that''s 200 x
100. The height is changed, but the width stays the same.

This behavior seems to vary depending on whether the image is in cache or
not.

Anybody know how to work around this problem?

Thanks!

推荐答案

曾几何时* Jesse *写道:
Once upon a time *Jesse* wrote:

我是gett在IE中真的很奇怪的行为,不知道如何绕过它。


我试图通过指定一个小于

image'的实际高度,如下所示:


var myImg = document.createElement(" img");

myImg。 src =" foo.jpg";

myImg.style.height =" 100px";


在Firefox中,这样做是正确的:图像自动缩放

从200 x 200到100 x 100.但在IE中,我最终得到的图像是200 x

100.高度是更改,但宽度保持不变。


此行为似乎会有所不同,具体取决于图像是在缓存中还是

而不是。


有谁知道如何解决这个问题?
I''m getting really strange behavior in IE, not sure how to get around it.

I''m trying to scale an image by specifying a height that''s less than the
image''s actual height, like this:

var myImg = document.createElement("img");
myImg.src = "foo.jpg";
myImg.style.height = "100px";

In Firefox, this does the right thing: the image is automatically scaled
from 200 x 200 to 100 x 100. But in IE, I end up with an image that''s 200 x
100. The height is changed, but the width stays the same.

This behavior seems to vary depending on whether the image is in cache or
not.

Anybody know how to work around this problem?



如果你真的必须这样做,试着设置* width *的百分比。但是为什么

不只是将图像的大小改为你想要显示的大小?


-

/ Arne


SeaMonkey的骄傲用户。获取免费副本:
http://www.mozilla.org/ projects / seamonkey /


Jesse写道:
Jesse wrote:

我的行为真的很奇怪在IE浏览器中,不知道怎么回事

它。


我试图通过指定高度
来缩放图像
I''m getting really strange behavior in IE, not sure how to get around
it.

I''m trying to scale an image by specifying a height



您有什么具体需要这样做,而不是提供与页面大小完全相同的

图像?许多浏览器会扭曲使用height和width属性调整大小的图像,有些浏览器会在页面加载时跳转到页面。

What specific need do you have for doing this, rather than supplying an
image of exactly the size the page needs? Many browsers will distort an
image resized with the height and width attributes, and some cause the
page to jump around as the page loads.


小于图像的实际高度,如下所示:


var myImg = document.createElement(" img") ;

myImg.src =" foo.jpg" ;;

myImg.style.height =" 100px" ;;
that''s less than the image''s actual height, like this:

var myImg = document.createElement("img");
myImg.src = "foo.jpg";
myImg.style.height = "100px";



那么当您为此代码添加宽度时会发生什么? (

您的访问者是否已禁用,无法使用或被
公司防火墙剥离?会发生什么?)

So what happens when you add the width to this code? (What happens when
your visitor has JavaScript disabled, unavailable, or stripped by a
corporate firewall?)


在Firefox中,这样做是正确的:图像自动地从200 x 200到100 x 100缩小为
。但在IE中,我最终得到了一个图像

'是200 x 100.高度改变了,但宽度保持相同。
In Firefox, this does the right thing: the image is automatically
scaled from 200 x 200 to 100 x 100. But in IE, I end up with an image
that''s 200 x 100. The height is changed, but the width stays the
same.



典型的IE行为?

Typical IE behavior?


有谁知道如何解决这个问题?
Anybody know how to work around this problem?



使用图形编辑器调整第二张图像大小。


-

-bts

-警告:我为草坪鹿刹车

Make a second image resized with your graphic editor.

--
-bts
-Warning: I brake for lawn deer


如果你真的必须这样做,试着设置* width *百分比。但为什么
Try to set the *width* in percent, if you really must do that. But why

不只是将图像的大小更改为您想要显示的大小?
not just change the size of the image to the size you like to show it?



在此应用中,宽度会有所不同;它的高度必须保持不变。


我正在使用1TB的数据库。生成和生成是不切实际的。商店

这些图片在服务器端的尺寸更大。


我也尝试加载图片,然后获得高度&宽度在

javascript中,并将两者都设置为新的所需大小。这有效 - 但只有当IE感觉像是给我图像的尺寸时,只有

。当图像被缓存时,IE倾向于报告高度和高度。宽度为0,这不是很有帮助。


任何人都知道如何解决这个问题?

In this application, the width will vary; it''s the height that has to be
held constant.

I''m working with a database of 1TB. It''s not practical to generate & store
more sizes of these images on the server side.

I also tried loading the image, then getting the height & width in
javascript, and setting both to the new desired size. This works -- but only
when IE feels like giving me the dimensions of the image. When the image is
cached, IE tends to report height & width as 0, which isn''t very helpful.

Anyone know how to solve this problem?


这篇关于在IE中缩放图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆