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

jquery实现iframe自适应高度代码

2013-09-05 20:23 796 查看
iframe框架高度自适应功能在以前我们都是利用js来实现,现在有了jquery控制可以快速实现,下面来看实现有需要的朋友可以看看。
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>jquery » iframe sizing</title>
<link rel="stylesheet" type="text/css教程" media="all" href="css/master.css" />
<script type="text/网页特效" src="js/jquery-1.4.3.min.js"></script>
<script type="text/javascript" src="js/jquery.iframe-auto-height.plugin.js"></script>
</head>
<body>
<div id="container">
<h1>
jquery » iframe sizing
</h1>
<p>
this demo uses <a href="http://jquery.com/">jquery</a> to dynamically size iframes based on content height.
original code by nathan smith, see <a href="http://sonspring.com/journal/jquery-iframe-sizing">original article</a>.
</p>
<p>
now a jquery plugin, download from github <a href="http://github.com/house9/jquery-iframe-auto-height">http://github.com/house9/jquery-iframe-auto-height</a>
and view the readme file.
</p>
<p>
best viewed locally with firefox.
 | 
<a href="index2.html">index2</a>
 | 
<a href="index_with_tables.html">index_with_tables</a>
</p>
<iframe src="panoramic.html" class="photo" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_1.html" class="column" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_1.html" class="column" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_1.html" class="column" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_1.html" class="column" scrolling="no" frameborder="0"></iframe>
<div class="clear"> </div>
<iframe src="iframe_2.html" class="column" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_2.html" class="column" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_2.html" class="column" scrolling="no" frameborder="0"></iframe>
<iframe src="iframe_2.html" class="column" scrolling="no" frameborder="0"></iframe>
<div class="clear"> </div>
</div>
<!-- end #container -->

<script type="text/javascript">
// match all iframes / use jquery or alias $
jquery('iframe').iframeautoheight();

// only panoramic.html iframe with some extra height
// $('iframe.photo').iframeautoheight({heightoffset: 50});

// notes: you can wrap this in document ready if you like
// but ie8 didn't always like it
</script>


</body>
</html>
这样做起比较js要方便了许多,并且我们只要利用 jquery('iframe').iframeautoheight();来自适应高度就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: