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.htmlThe 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.htmlThis is a screenshot of both examples:
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
精彩评论