加载在jquery中不起作用,请帮忙

时间:2010-07-23 07:24:47

标签: javascript jquery css

我正在尝试修复一个jquery问题,我的代码是

<script language="javascript">
    $(document).ready(function() {
         //if the document is ready
        $('#img').load(function() { 
            //if the image is loaded
            pic_real_height = this.height;
            //finding the height of the image
            $('#img').css('margin-top', 150 - pic_real_height / 2 + 'px');  //setting the margin-top to align the image verticall middle in the container<br>
        });  
    });
</script>

此脚本适用于除IE和Opera之外的所有浏览器,如何解决此问题? 实际上我想在容器(div)

中垂直设置图像

谢谢你们

1 个答案:

答案 0 :(得分:1)

pic_real_height = $(this).height();