Nic*_*een 7 jquery jquery-ui-tabs twitter-bootstrap
刚开始探索Twitter的Bootstrap,我喜欢我所看到的.但是我有一个关于如何实现包含iFrame的Tabs的查询.我知道iFrame非常糟糕,但正确使用对于显示不同类型的数据非常有用.
我有jQueryUI选项卡的经验,它允许我在选项卡内显示iFrame.但是我找不到任何与Bootstrap相同的文档.
从jQueryUI的角度来看,我过去曾这样做过:
<div id="tabs">
<ul>
<li><a class="tabref" href="#tabs-1" rel="page1-iframe.html">Page 1 Title</a></li>
<li><a class="tabref" href="#tabs-2" rel="page2-iframe.html">Page 2 Title</a></li>
</ul>
<div id="tabs-1"></div>
<div id="tabs-2"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
以上是比标准的jQueryUI Tab实现更先进.它允许我偏移iFrame的负载,直到用户选择选项卡,这是加载大量页面时的最佳方式.
但是,我看不到与Bootstrap类似的方式.
在这里寻找指点.
干杯尼克
下面是使用自定义数据属性和一些jQuery的解决方案.或者看看Bootstrap"LazyLoading"iFrames的相同解决方案的工作jsFiddle .
<div class="container">
<div class="row">
<div class="span12">
<ul class="nav nav-tabs" id="myTabs">
<li class="active"><a href="#home" data-toggle="tab">Home</a></li>
<li><a href="#dpa" data-toggle="tab">DPA</a></li>
<li><a href="#twon" data-toggle="tab">Antwon</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="home">
<p>test</p>
</div>
<div class="tab-pane" id="dpa" data-src="http://www.drugpolicy.org/">
<iframe src=""></iframe>
</div>
<div class="tab-pane" id="twon" data-src="http://player.vimeo.com/video/37138051?badge=0">
<iframe src="" width="500" height="203" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> <p><a href="http://vimeo.com/37138051">ANTWON ? HELICOPTER</a> from <a href="http://vimeo.com/tauszik">Brandon Tauszik</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
</div>
</div>
</div>
</div>
</div>?
<script>
$('#myTabs').bind('show', function(e) {
// identify the tab-pane
paneID = $(e.target).attr('href');
// get the value of the custom data attribute to use as the iframe source
src = $(paneID).attr('data-src');
//if the iframe on the selected tab-pane hasn't been loaded yet...
if($(paneID+" iframe").attr("src")=="")
{
// update the iframe src attribute using the custom data-attribute value
$(paneID+" iframe").attr("src",src);
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24172 次 |
| 最近记录: |