我正在操纵iframe,使其等于其包含的图像的尺寸。我快到了。问题是,我绝对可以获得img的高度。但是通过' auto'来推断图像的宽度。属性。但是我不能对iframe执行相同操作,iframe只接受像素和百分比。
$(this).contents().find('img').load(function(){
//get the computed styles of the img via the computedstyle.js plugin
var myCSS = $(this).getCSS();
//grab the height and width of the newly loaded image
var myY = myCSS.height.slice(0, - 2);
if(myY>heightRef){
$(this).closest(".photoset_row").css({height: heightRef});
$(this).closest(".photoset_row").css({width: 'auto'});
myFrame.attr('height',(heightRef-0));
myFrame.attr('width',________); //auto is not accepted
}else{
var myX = myCSS.width.slice(0, - 2);
$(this).closest(".photoset_row").css({height: heightRef});
$(this).closest(".photoset_row").css({width: myX});
myFrame.attr('height',myY);
myFrame.attr('width',myX);
}
...
这是一个滑坡,试图获得图像的计算宽度,可能已加载也可能未加载。
我怎么能这样做?!