473,395 Members | 2,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Hide All Except One Tabs showing hidden content brriefly

I am using jQuery & hideAllExcept.js from this demo tute
http://enure.net/dev/hide-all-except-one/

The issue is that on a page with other content, the images I have placed in the toggleThis divs loads before everything is ready and they briefly appear stacked below, before disappearing when they snap into place. hiddeAllExcept.js does use $(document).ready(function() {

I had this same issue with jCarousel, only the dynamically loaded version did not do this. Any input on a workaround appreciated.

Expand|Select|Wrap|Line Numbers
  1. <!-- import the DOM logic from external javascript files -->
  2.         <script type="text/javascript" src="http://enure.net/_js/jquery.min.js"></script>
  3.         <script type="text/javascript" src="http://enure.net/dev/hide-all-except-one/hideAllExcept.js"></script>
  4.  
  5. <style type="text/css">
  6.  .hide { display: none; } /* required */
  7.  body { background-color: #ffffff; }
  8.  #wrapp { margin: 0; padding: 0; width:300px;   background-color: white;}
  9.  #ccc;border-right: 1px solid #ccc;border-bottom: 1px solid #ccc; font-family: 'arial',  helvetica, sans-serif; font-weight: bold; font-size: 70%;}
  10.  ul { padding-left: 0; padding-bottom:0 }
  11.  li { float: left; display: block; margin-right: 0.1em; }
  12.  ul#buttons {
  13.   margin: .1em .1em .1em .1em;
  14.   font-family: arial, helvetica, sans-serif;
  15.   font-weight: bold;
  16.   font-size: 70%;
  17.  
  18.  }
  19.  ul#buttons li { padding: .1em .1em .1em .1em; border-right: 1px solid #000; border-left: 1px solid #000; border-top: 1px solid #000; border-bottom: 1px solid #000; border-bottom: 0; 
  20.   background-image: url(tabsBG.gif);}
  21.  div#toggleThis { margin-top: 0; margin-bottom:0; border-left: 1px solid #ccc;border-right: 1px solid #ccc;}
  22.  div#toggleThis div {  padding: 0; color: #000; border-left:#eee; font-family: georgia, serif; }
  23.  a, a:link, a:visited { color: #111; text-decoration: none; }
  24.  a.active, a:hover { color: red; }
  25.  
  26. </style>
  27.  
  28.     </head>
  29.     <body>
  30.        <div id="wrapp">
  31.  
  32.  
  33.             <ul id="buttons">
  34.                 <li><a class="toggle" href="#one">&nbsp;one&nbsp;</a></li> <!-- The js looks for any links with a class of 'toggle'. It then makes visible the id which matches the href. -->
  35.                 <li><a class="toggle" href="#two">&nbsp;two&nbsp;</a></li>
  36.                 <li><a class="toggle" href="#three">&nbsp;three&nbsp;</a></li>
  37.             </ul>
  38.            <div id="toggleThis"> <!-- the js looks for an id of 'toggleThis' and divs inside of it. -->
  39.                 <div id="one"><br /><br /><br />DIV ONE CAN HAVE ANYTHING IN IT INCLUDING IMAGES
  40. </div>
  41.                 <div id="two"><br /><br /><br />DIV TWO CAN HAVE ANYTHING IN IT INCLUDING IMAGES
  42.             </div>
  43.                 <div id="three"><br /><br /><br />DIV THREE  CAN HAVE ANYTHING IN IT INCLUDING IMAGES
  44.  
  45. </div>
  46.             </div>
  47.  
  48.  
  49. </div>
  50.  
Jun 23 '08 #1
7 4642
acoder
16,027 Expert Mod 8TB
You'll want to hide them to begin with. Either add the class hide to each div, or just add display:none to toggleThis until the document is ready.
Jun 24 '08 #2
Thanks for your help. I tried an inline style of display:none for divs two & three. This kept them hidden even when button divs were clicked. I then tried

div#toggleThis div.hide and div#toggleThis.hide neither worked.

Or did you mean I should add this to the style as it is div two & three that show below the wrapp div until the page loads

#wrapp { margin: 0; padding: 0; width:300px; background-color: white;}
#one{ margin: 0; padding: 0; width:300px; height:218px;}
#two.hide{ margin: 0; padding: 0; width:300px; height:218px;}
#three.hide{ margin: 0; padding: 0; width:300px; height:218px;}

That did not seem to work either :(

Do you think I need to change the hideAllExcept.js to include a 2nd (document).ready(function(){ applied to the toggleThis divs?

Note I did have to use jQuery.noConflict as the page this needs to go on uses prototype.js

Expand|Select|Wrap|Line Numbers
  1. jQuery.noConflict();
  2. jQuery(document).ready(function() {
  3.     var hash = window.location.hash;
  4.  
  5.     (!hash) ?  
  6.         hideAllExcept('#' + jQuery('#toggleThis > div:first').attr('id')) 
  7.             : hideAllExcept(window.location.hash);
  8.  
  9.     jQuery('a.toggle').click(function() {
  10.         var href = jQuery(this).attr('href');
  11.         hideAllExcept(href);
  12.     });
  13. });
  14.  
  15. function hideAllExcept(el) {
  16.     jQuery('#toggleThis div').addClass('hide');
  17.     jQuery(el).removeClass('hide');
  18.  
  19.     jQuery('a.toggle').removeClass('active');
  20.     jQuery('a[href="' + el + '"]').addClass('active');
  21.  
  22. }
Jun 24 '08 #3
acoder
16,027 Expert Mod 8TB
I think it'd be a good idea to use the class instead, so if you set the class of divs two and three to "hide". See if that works.
Jun 24 '08 #4
OK so I tried this as changing all 3 divs to class rather than ID collapsed all 3

.one{ margin: 0; padding: 0; display:block; width:300px; height:218px;}
.two.hide{ margin: 0; padding: 0; width:300px; height:218px;}
.three.hide{ margin: 0; padding: 0; width:300px; height:218px;}

I can see .one but the show hide toggleThis is not working now for .two & .three.

I even changed
hideAllExcept('#' + jQuery('#toggleThis > div:first').attr('id'))

to this
hideAllExcept('#' + jQuery('#toggleThis > div:first').attr('class'))

As you probably guessed I'm one of those people that use jQuery without a real good idea of exactly how the library works.
Jun 24 '08 #5
acoder
16,027 Expert Mod 8TB
No, what I meant was adding the class to the HTML, i.e.
[html]<div id="two" class="hide">[/html]so the two divs will initially be hidden. hideAllExcept should remove the class to display it again. I haven't tested, but that's the general idea.
Jun 25 '08 #6
Thank you for your patience! That worked. I had tried it as an inline style but not as a class.

Edited to add. I learned a lot from you.
Jun 25 '08 #7
acoder
16,027 Expert Mod 8TB
Glad to hear it! Post again if you have more questions.
Jun 25 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: horndude77 | last post by:
Ok, this might be for a web designing group, but here's my problem. I'm trying to make a web page with tabs which you can navigate between without the page reloading. I have one set of tabs working...
4
by: jerryyang_la1 | last post by:
I've found this script that allows be to hide/show form elements.. <script language="JavaScript"><!-- var toggle = true; function show(object) { if (document.layers && document.layers)...
3
by: Merlin | last post by:
Hi there, I am trying to create a form with an dynamic field that can be shown or hidden. As I saw for example on google it is possible with JS to show a layer and move the content underneath...
11
by: jimstruckster | last post by:
I have a table with 10 rows, I want all rows except for the first to be hidden when the page first opens up. If the user puts a value in a text box in the first row then I want the second row to...
1
by: lisa232 | last post by:
Hi All, I have a problem with some javascript code. I am trying to toggle display between two tables upon change of a select box ( to alternate between search forms) eg. one called...
1
by: pamate | last post by:
hi, I want to show hide layers. I am able to show and hide layers but i am facing problem that, cant view the cursor in Mozilla,but i can type in input text box, its overlapping the layers. ...
47
by: SOLAV | last post by:
This is the only working way to completely hide your JavaScript code from the client just like PHP or ASP code. Here we'll need the help of PHP. Here is the code: index.php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.