开发者

jQuery 1.4 Dynamically created images aspect ratio incorrect in IE8 and max-width [duplicate]

开发者 https://www.devze.com 2022-12-17 03:14 出处:网络
This question already has answers here: IE8 non-compatibility mode, image with max-width and height:auto
This question already has answers here: IE8 non-compatibility mode, image with max-width and height:auto (6 answers) Closed 2 years ago.

After upgrading to jQuery 1.4, when I try to add an image to a page dynamically using jQuery 1.4 in IE8, the image will lose the correct aspect ratio. This appears to affect only IE8 (IE7 and Firefox work fine) with jQuery 1.4 (1.3.2 works fine). Including the jQuery compatability file does not fix the problem.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" language="javascript"
        type="text/javascript"></script>
    <!-- Switching to 1.3.2 fixes the problem -->
    <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" language="javascript"
        type="text/javascript"></script>-->
    <script type="text/javascript">
        $(document).ready(function() {
            var dynImg = $('<img></img>').attr('src', 'http://www.google.开发者_StackOverflowcom/intl/en_ALL/images/logo.gif');
            $('body').append(dynImg);
        });
    </script>
    <style type="text/css">
        img
        {
            max-width: 5em;
        }
    </style>
</head>
<body></body></html>


Set CSS zoom property:

img {
    zoom: 100%;
}
0

精彩评论

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

关注公众号