Results 1 to 4 of 4

Thread: <ul> <li> with jquery question

  1. #1
    Join Date
    Oct 2012
    Posts
    180
    Thanks
    22
    Thanked 1 Time in 1 Post

    Default <ul> <li> with jquery question

    The subcategories tend to show for a split second on load or refresh. Is there a way to keep it shut and show them only when you click on the CATEGORY link?

    Code:
    <script src="http://www.google.com/jsapi"></script>
    <script type="text/javascript">
    google.load("jquery", "1");
    </script>
    <script type="text/javascript">
    $(document).ready(function() {
      $('#category ul').hide();
      $('#category li a').click(
        function() {
            $(this).next().slideToggle('normal');   
          }
        );
    });
    </script>
    
    <style type="text/css">
    #category, #category ul {margin: 0px; padding: 0px; text-align: left;  list-style: none;}
    #category li {cursor: pointer; }
    </style>
    
    
    <ul id="category">
    
    <li><a onclick="javascript:void(0);">CATEGORY</a><ul>
    
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    <li><a href="/">Subcategory</a></li>
    
    </ul></li>
    </ul>
    Last edited by qwikad.com; 09-15-2014 at 05:37 PM.

  2. #2
    Join Date
    Mar 2010
    Location
    Florida
    Posts
    512
    Thanks
    9
    Thanked 61 Times in 59 Posts

    Default

    Are you wanting something like this?
    http://jsfiddle.net/tfsevnzx/1/
    -DW [Deadweight]
    Resolving your thread: First Post: => EDIT => Lower right: => GO ADVANCED => Top Advance Editor drop down: => PREFIX:Resolved

  3. The Following User Says Thank You to Deadweight For This Useful Post:

    qwikad.com (09-16-2014)

  4. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Without looking at your code or Deadweight's, the simple answer is yes. Use CSS. Display none is tempting and can work. In most cases you will have even better results with with visibility hidden combined with position absolute. In the stylesheet. set the elements that you don't want to have flicker on load to visibility hidden and position absolute. Then in the script, the first time you want to see them, have javascript set them to visibility visible, and - well often position absolute can remain, if not, change that to whatever you need. These initial hidden states can be achieved with a class name. If you do it that way, just have your script remove that class name once you want to see the element.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. The Following User Says Thank You to jscheuer1 For This Useful Post:

    qwikad.com (09-16-2014)

  6. #4
    Join Date
    Sep 2007
    Location
    The Netherlands
    Posts
    1,881
    Thanks
    49
    Thanked 266 Times in 258 Posts
    Blog Entries
    56

    Default

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
    $("#category ul").css({opacity: 0});
    $('#category ul').hide();
    $('#category li a').click(
    function() {
    $(this).next().slideToggle('normal'); 
    setTimeout("$('#category ul').css({opacity: 1})",200);  
    }
    );
    });
    </script>

  7. The Following User Says Thank You to molendijk For This Useful Post:

    qwikad.com (09-16-2014)

Similar Threads

  1. question about JQuery
    By gib65 in forum JavaScript
    Replies: 4
    Last Post: 09-09-2012, 11:26 PM
  2. php + ajax + jquery + sql question
    By scifirocket2 in forum JavaScript
    Replies: 0
    Last Post: 09-23-2010, 09:26 PM
  3. jQuery noob question
    By RipzCurlz in forum JavaScript
    Replies: 8
    Last Post: 01-11-2010, 05:11 PM
  4. jquery jcarousel question
    By sluis in forum JavaScript
    Replies: 0
    Last Post: 10-29-2009, 12:20 AM
  5. Jquery Menu Question
    By atomgroom in forum CSS
    Replies: 2
    Last Post: 04-17-2009, 08:17 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •