问题
I have:
$("#fancybox-manual-b").click(function() {
$.fancybox.open({
href : 'iframe.html',
type : 'iframe',
padding : 5
});
});
<li><a class="fancybox fancybox.iframe" href="iframe.html">Iframe</a></li>
however I would like to Adjust size of iframe depending on user screen's size.
I was trying something like:
width = $(window).width() -80;
heigth= $(window).height() -80;
Is this correct?, how to use it in code?
回答1:
Alternatively, you can also try this..
<script type="text/javascript">
$(document).ready(function () {
$("a.iframe").fancybox({
'width': 800,
'height': 500,
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'type': 'iframe'
});
});
</script>
ND
回答2:
Try this,
function ResizeIframe(iframe) {
var iframeBody = (iframe.contentDocument) ? iframe.contentDocument.body : iframe.contentWindow.document.body;
var height = (iframeBody.scrollHeight < iframeBody.offsetHeight) ? iframeBody.scrollHeight : iframeBody.offsetHeight;
height = height + 10;
$(iframe).height(height);
}
<iframe id="idFrm" src="URL" frameborder="0" clientidmode="Static" scrolling="no" height="35px" width="98%" onload="javascript:ResizeIframe(this);"></iframe>
I have used it and works like charm in all browsers. Call it onload of your
ND
来源:https://stackoverflow.com/questions/15357047/adjust-width-and-height-for-iframe-depending-on-screen-size