iframe动态调整大小
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iframe动态调整大小相关的知识,希望对你有一定的参考价值。
javascript code to facilitate dynamic re-sizing of an iframe at the same time as the browser window is re-sized, as well as making sure that the frame scales proportionally to its width and height.
<script type="text/javascript"> $.noConflict(); function adjustIframes() { $('iframe').each(function(){ var $this = $(this), proportion = $this.data( 'proportion' ), w = $this.attr('width'), actual_w = $this.width(); if ( ! proportion ) { proportion = $this.attr('height') / w; $this.data( 'proportion', proportion ); } if ( actual_w != w ) { var h = Math.round( actual_w * proportion ); if (!isNaN(h)) { if (console && console.log) console.log("Resizing iframe to height: " + h); $this.css( 'height', h + 'px' ); if ($this.get(0).contentWindow.postMessage) { $this.get(0).contentWindow.postMessage('resize', 'your website here'); } } } }); } $(window).on('resize load',adjustIframes); }); </script>
以上是关于iframe动态调整大小的主要内容,如果未能解决你的问题,请参考以下文章
使用 jQuery 按比例调整 iframe 的大小以适合 DIV