Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery tabs, unformatted list flashing up after an jQuery HTML reload in Firefox

Tags:

jquery

tabs

I am using the latest jQuery Tabs, and all of my tabs (and other content above them) are within a containing Div. There is a form in one of the tabs, and when the form is submitted, it is processed via AJAX, and then the returned HTML replaces the entire containing Div. This returning HTML includes the tabs again.

After the HTML is replaced, I rebind the jQuery functionality to the list:

$('#tabs').tabs( { fx: { opacity: 'toggle' } } );

Having read other questions, I am using class="ui-tabs" on the UL and class="ui-tabs-hide" on the LI, to hide everything before it's formatted.

In IE8, and Chrome this is working fine. However in Firefox, the unformatted list is showing briefly between the HTML refresh and the tabs being formatted (it does very briefly on the first load too).

Any ideas how to avoid this please?

like image 838
Newmania Avatar asked Nov 27 '22 19:11

Newmania


1 Answers

From jQueryUI docs:

...prevent a FOUC (Flash of Unstyled Content) before tabs are initialized

Add the necessary classes to hide an inactive tab panel to the HTML right away - note that > this will not degrade gracefully with JavaScript being disabled:

<div id="example" class="ui-tabs">

<div id="a-tab-panel" class="ui-tabs-hide"> </div>

</div>

The class="ui-tabs-hide" should go on each panel, not the tab list items.

This won't necessarily fix the list being unstyled; If you're implementing the above properly and still getting the FOUC, you should hide the list's parent element until you have loaded the new content and tabify'd the list. You could use the $().hide() and .show() methods to do this.

like image 75
kbanman Avatar answered Dec 05 '22 03:12

kbanman