【发布时间】:2011-06-18 21:24:02
【问题描述】:
我在 Firefox 和 IE8 中使用带有 iframe 的 jQuery 对话框时遇到了奇怪的显示问题。
我已经在 iframe 之外测试了页面本身,问题没有重现,只有在 jQuery 对话框内时。
问题
图片实际尺寸:300x225 图片显示尺寸:400x300
JS 代码 - 父页面
$(document).ready(function() {
var img = $('.photoLink');
var imgSrc = img.attr('src');
$('.photoLink').photoDialog({
id: imageID,
onClose: function() {
img.attr('src', imgSrc + '&rand=' + (new Date()).getTime());
}
});
});
$.fn.photoDialog = function(options) {
var defaults = {
autoOpen: false,
title: 'Photo Tool',
minHeight: 560,
minWidth: 540
onClose: function(){}
};
var opts = $.extend(defaults, options);
return this.each(function() {
$this = $(this);
that =$(this);
var $dialog = $('<div>')
.html('<iframe src="' + opts.url + '?sn=' + opts.id + '" width="' + (opts.minWidth - 20) + '" height="' + (opts.minHeight - 20) + '" style="border: none;" scrolling="no"></iframe>')
.dialog({
autoOpen: opts.autoOpen,
title: opts.title,
minHeight: opts.minHeight,
minWidth: opts.minWidth,
modal: true,
close: function() {
opts.onClose.call(that);
}
});
$this.click(function() {
$dialog.dialog('open');
return false;
});
});
};
正文代码 - 子页面
<div id="photo_holder" runat="server">
<asp:Image ID="image_photo" style="display: none;" runat="server" />
</div>
样式代码 - 子页面
#photo_holder {
position: relative;
float: left;
padding: 10px;
width: 300px;
height: 300px;
}
.portrait { height: inherit; width: auto; }
.landscape { height: auto; width: inherit; }
JS 代码 - 子页面
$(document).ready(function () {
$('#image_photo').load(function () {
$this = $(this);
if ($this.width() > $this.height()) {
$this.attr('class', 'landscape');
}
else {
$this.attr('class', 'portrait');
}
}).fadeIn('slow');
});
图像的类别是根据图像尺寸动态设置的。
图片路径是在后面的代码中设置的,没有做任何样式或调整大小。
图片在上传时调整为不大于 300x300。
在 Chrome 和 Safari 中显示是正确的,但在 IE 和 FF 中由于某种原因它会放大图像。
【问题讨论】:
标签: asp.net jquery iframe jquery-ui-dialog