Jquery 每次内容更改时,使用iFrame内容更新fancybox的大小
我正在使用fancybox 1.3.1。现在,我将一个iFrame加载到Fancybox中,它可以正常工作。在iFrame中,用户从一步到另一步。在某些步骤中,内容的高度会发生变化。如何更新iFrame的高度 我尝试了jQuery postMessage:Jquery 每次内容更改时,使用iFrame内容更新fancybox的大小,jquery,iframe,resize,fancybox,postmessage,Jquery,Iframe,Resize,Fancybox,Postmessage,我正在使用fancybox 1.3.1。现在,我将一个iFrame加载到Fancybox中,它可以正常工作。在iFrame中,用户从一步到另一步。在某些步骤中,内容的高度会发生变化。如何更新iFrame的高度 我尝试了jQuery postMessage: <script type="text/javascript" src="fileadmin/templates/lib/jquery.ba-postmessage.min.js"></script> <scrip
<script type="text/javascript" src="fileadmin/templates/lib/jquery.ba-postmessage.min.js"></script>
<script type="text/javascript">
$("#fancylink").fancybox({
'type' : 'iframe',
'width' : 700,
'height' : 450,
'autoScale' : false
});
</script>
<script type="text/javascript">
// set inital height
var if_height = 450;
$(document).ready(function() {
if($.receiveMessage){
$.receiveMessage(function(e){
// Get the height from the passsed data.
var h = Number( e.data.replace( /.*if_height=(\d+)(?:&|$)/, '$1' ));
if ( !isNaN( h ) && h > 0 && h !== if_height ) {
// Height has changed, update the iframe.
// checking min and max height
h=(h<450)?450:h;
$("#fancybox-frame").height( if_height = h );
}
});
}
});
</script>
但在这里什么都没有发生(没有调整大小)。我认为这只是fancybox的第一次加载。但也是第一次什么也没发生
我的问题有解决方案吗?还是只能使用固定尺寸
解决方案:
因此,我添加了以下代码,它似乎可以按预期工作:
$("#fancybox-inner").height( h );
$("#fancybox-wrap").height( h+20 );
$.fancybox.center();
我将测试一点,但我认为这可以工作。如果fancybox高于当前页面,会发生什么情况?页面会变大吗?您可以执行以下操作
function updateMyFancyBox() {
$.fancybox.wrap.height($.fancybox.inner.height() + $('div#yourContentDiv').height());//increase fancybox height by adding your div height.
$.fancybox.update();//Fancybox will re-size according to new size, if it exceeds size limit, it will show scroll bar.
}
你可以像下面这样做
function updateMyFancyBox() {
$.fancybox.wrap.height($.fancybox.inner.height() + $('div#yourContentDiv').height());//increase fancybox height by adding your div height.
$.fancybox.update();//Fancybox will re-size according to new size, if it exceeds size limit, it will show scroll bar.
}
function updateMyFancyBox() {
$.fancybox.wrap.height($.fancybox.inner.height() + $('div#yourContentDiv').height());//increase fancybox height by adding your div height.
$.fancybox.update();//Fancybox will re-size according to new size, if it exceeds size limit, it will show scroll bar.
}