Chrome中jQuery图像的高度/宽度

问题描述

| 我正在尝试获取图像的宽度/高度,以设置父容器的宽度/高度。这是我这样做的代码:
var current_img = temp.find(\".test-img\").attr(\'src\',c[\'img\']).addClass(\"active-image\");
然后我通过获得图像的宽度/高度
current_img.css(\'width\');
我遇到的问题是chrome在图片之前加载了jscript,因此该函数返回null。所以我把这段代码放在一起:
$(\".test-img\").each(function (index) {
                        $(this).load(function() {
                            imgwidth = $(this).css(\'width\');
                            imgheight = $(this).css(\'height\');
                                if (imgwidth != \"0px\" && imgheight != \"0px\")
                                    $(this).parent().addClass(\'center\').css({\'width\' : imgwidth,\'height\' : imgheight});
                                    });
                    });
第一次加载页面时,这似乎工作正常,但是在调用该函数时,它返回null。另外,当我在本地打开页面时,它似乎可以正常工作,但是当托管在我的网络服务器上时,我会遇到此问题。 这是有问题的页面:http://swolepersonaltraining.com/testing/sorter/     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)