开发者

JavaScript: Image doesn't scale in IE when dynamically added

when I dynamically add an image to a div the image doesn't scale when you resize the window in Internet Explorer.

I think it's more clear if I show two really simple examples:

The following example doesn't use JavaScript it's just plain html and it does what I want.

http://www.开发者_运维技巧friendly-stranger.com/halp/ie-width/index.html

The next one uses JavaScript and if you resize the width of your browser window the image doesn't scale only the width gets smaller.

http://www.friendly-stranger.com/halp/ie-width/bad.html

This is a screenshot of both examples:

JavaScript: Image doesn't scale in IE when dynamically added

(source: friendly-stranger.com)

The JavaScript code I use:

<script type="text/javascript">
    $(function(){
        var img = new Image();
        img.src = 'Koala.jpg';
        $('div').append(img);
    }); 
</script>


<script type="text/javascript">
    $(function(){
        var img = new Image();
        img.src = 'Koala.jpg';
        img.style.height = 'auto';
        $('div').append(img);
    }); 
</script>

try this, i hope it'll work

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜