如何避免动态生成的 jQuery UI 选项卡上的 FOUC
我使用 jQUery UI 选项卡动态创建多个选项卡 - 这些选项卡是使用视图页面上的 foreach
创建的,如下所示(一些 codeigniter 标记):
<script type="text/javascript">
$(function($) {
$('#plants').tabs('paging', { follow: true } );
});
</script>
<div id="plants">
<ul>
<?php foreach ($plants as $row):
echo '<li><a href="#tabs-'.$row->plant_id.'">'.$row->plant_name.'</a></li>';
endforeach; ?>
</ul>
<?php if (!empty($plants)):
foreach ($plants as $row): ?>
<div class="block" id="tabs-<?php echo $row->pet_id; ?>">
<div class="grid_6">
<p>
<?php echo '<h1>'.$row->pet_name.'</h1>'; ?>
etc...
</p>
</div>
</div>
<?php
endforeach;
else:
endif; ?>
</div>
如上所述,选项卡形成良好。问题在于无样式内容的良好闪现。它发生在 IE、Chrome、FF 上。
我已经尝试过 jQuery 文档中的 CSS 选项,但没有成功。
有一个简单的 JS,它在 上插入 CSS 样式,然后在特定的
id
上应用 {display:none}
--但这使我的面板消失,等待用户交互。我需要第一个面板在加载时对用户可见,以及顶部的其他选项卡 - 没有该死的 FOUC。
有谁知道如何明确解决 jQuery UI 选项卡上的 FOUC 问题?它看起来确实不太好,如果我不能解决这个问题,我可能不得不完全放弃选项卡。
非常感谢任何指示/路线图!
I dynamically create multiple tabs using jQUery UI tabs -- the tabs are created using a foreach
on a view page as follows (some codeigniter markup):
<script type="text/javascript">
$(function($) {
$('#plants').tabs('paging', { follow: true } );
});
</script>
<div id="plants">
<ul>
<?php foreach ($plants as $row):
echo '<li><a href="#tabs-'.$row->plant_id.'">'.$row->plant_name.'</a></li>';
endforeach; ?>
</ul>
<?php if (!empty($plants)):
foreach ($plants as $row): ?>
<div class="block" id="tabs-<?php echo $row->pet_id; ?>">
<div class="grid_6">
<p>
<?php echo '<h1>'.$row->pet_name.'</h1>'; ?>
etc...
</p>
</div>
</div>
<?php
endforeach;
else:
endif; ?>
</div>
As above the tabs are formed fine. Problem is the good ol' Flash Of Unstyled Content. It happens on IE, Chrome, FF.
I've tried the CSS option on the jQuery documentation, didn't work.
There's a simple JS that inserts a CSS style on <head>
and then applies a {display:none}
on a specific id
-- but that makes my panels disappear, waiting for user interaction. I need the first panel to be visible to the user on load, along with the other tabs on the top -- without the darn FOUC.
Does anyone know how to definitely resolve FOUC on jQuery UI tabs? It's really not looking good and I may have to abandon tabs altogether if I can't resolve this.
Any pointers/roadmaps are much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
JQuery UI 文档建议:
不确定您是否尝试过此操作,或者是否确实相关。
JQuery UI docs suggest:
Not sure if you have tried this, or if it is indeed relevant.
我发现在 head 标签中准备好的文档中触发 tabs() 函数可以防止我出现无样式的选项卡闪烁......
我用于通过 ajax 显示选项卡的另一种方法是一个 ajax 请求,它写入通过 jquery.tmpl 的选项卡。
I found that firing the tabs() function inside a document ready in the head tag prevented that unstyled flash of tabs for me....
A different approach I used for getting the tabs to show up via ajax, is a ajax request that writes the tabs via jquery.tmpl.
在 DOM 准备好之前隐藏整个页面(
元素),然后一旦 DOM 准备好,您就可以再次使 html 元素可见:
这是有效的,因为当在
head
中遇到此 javascript 时,html
元素就可用,在任何其他 DOM 元素(如body
)可用之前。Hide the entire page (the
<html>
element) before the DOM is ready, then once the DOM is ready you make the html element visible again:This works because the
html
element is available by the time this javascript is encountered in thehead
, before any other DOM elements (likebody
) are available.