您的位置:首页 > Web前端 > JQuery

开发小技巧:jQuery处理自适应内容高度的iframe

2013-04-16 00:00 661 查看
日期:2013-3-28 来源:GBin1.com





在线演示

之前我们发表过另一篇开发小技巧的文章 :开发小技巧:超简单的“回到顶端”按钮实现,喜欢的朋友可以点击来看。

前端开发中,我们往往需要处理iframe,可能有的时候希望iframe根据内容自适应高度以便不出现令人烦心的滚动条,下面这段代码可以帮助你实现类似功能。

$(document).ready(function()
{
// Set specific variable to represent all iframe tags.
var iFrames = document.getElementsByTagName('iframe');

// Resize heights.
function iResize()
{
// Iterate through all iframes in the page.
for (var i = 0, j = iFrames.length; i < j; i++)
{
// Set inline style to equal the body height of the iframed content.
iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
......

......

via 极客社区

来源:开发小技巧:jQuery处理自适应内容高度的iframe

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息