开发者

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

开发者 https://www.devze.com 2023-02-12 17:36 出处:网络
when I dynamically add an image to a div the image doesn\'t scale when you resize the window in Internet Explorer.

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

精彩评论

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