SitePoint Sponsor

User Tag List

Results 1 to 18 of 18

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JQuery UI Tabs Question

    Hi

    I am debugging a site that was previously developed (by another developer) which uses JQuery UI Tabs.

    The tabs pretty much work as required, except for 1 thing. When you move the mouse out of the tab container the First tab should become selected. Currently which tab is selected (my mouseover) will remain selected when moving mouse from container.

    Here is the basic structure:
    Code HTML4Strict:
    <div class="card_container">
    <div class="tabswrap">
    <ul class="tablink">
    <li class="first">First Tab</li>
    <li>Second Tab</li>
    <li>Third Tab</li>
    <li>Fourth Tab</li>
    <li class="last">Fifth Tab</li>
    </ul>
    <div class="clear"></div>
    <div class="panes">
    <div style="display: block;">First tab's content in here</div>
    <div style="display: block;">Second tab's content in here</div>
    <div style="display: block;">Third tab's content in here</div>
    <div style="display: block;">Fourth tab's content in here</div>
    <div style="display: block;">Fifth tab's content in here</div>
    </div>
    </div>
    </div>

    And the code (I believe that initialises this) is:
    Code JavaScript:
    $("ul.tablink").tabs("div.panes > div", {event:'mouseover'});

    So, when you mouse over a tab, the respective "pane" becomes visible.

    When you leave the container with the mouse, the most recently active tab/pane combination remains active. However we need (with jQuery) to make the first tab active (and its respective "pane" visible). Hope that makes sense.

    Any help would be greatly appreciated.

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    This might do the trick:

    Code javascript:
    $('.card_container').mouseleave(function () {
        $(this).tabs({selected, 0});
    });

    Edit:

    Not quite - see below
    Last edited by paul_wilkins; Apr 17, 2011 at 05:46.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, but nope, the tabs and panes completely disappear. "display: none"

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by LuckyB View Post
    Thanks, but nope, the tabs and panes completely disappear.
    Please link to a test page, so that we can help you further.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, will try. This is on a development environment, and not live.

    Will see what I can do.

  6. #6
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, please see here:
    Tabs test

    Many thanks

  7. #7
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    I have to go now, but it's the select method (not selected) that you'll see at the tabs methods documentation.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  8. #8
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I had tried that too, and couldn't get it to work with:
    $(this).tabs("select",1); (or 0)

  9. #9
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any more suggestions?

  10. #10
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anyone? Can't work this out.

    See test page: Page 1

    I want the mouse out (of container) to return focus to Tab 1.

    Thanks

  11. #11
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Well if it helps, this simple test page provides a working demonstration of the technique you want to apply.

    Code html4strict:
    <html>
    <head>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css" type="text/css" media="all" /> 
    <link rel="stylesheet" href="http://static.jquery.com/ui/css/demo-docs-theme/ui.theme.css" type="text/css" media="all" /> 
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript"></script> 
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js" type="text/javascript"></script> 
    </head>
    <body>
    <div id="tabs"> 
    	<ul> 
    		<li><a href="#tabs-1">Nunc tincidunt</a></li> 
    		<li><a href="#tabs-2">Proin dolor</a></li> 
    		<li><a href="#tabs-3">Aenean lacinia</a></li> 
    	</ul> 
    	<div id="tabs-1"> 
    		<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p> 
    	</div> 
    	<div id="tabs-2"> 
    		<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p> 
    	</div> 
    	<div id="tabs-3"> 
    		<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p> 
    		<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p> 
    	</div> 
    </div> 
    <script>
    $(function() {
        $('#tabs')
            .tabs({event:'mouseover'})
            .mouseleave(function () {
                $(this).tabs('select', 0);
            });
    });
    </script>
    </body>
    </html>
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  12. #12
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul

    Thanks much, demo works great. I just can't get the same jQuery code working on my demo:
    Test

    Am I not applying it to the right Div? I've tried it on nearly all "containing" divs, and this is as good as I could get it.

    Again thanks so much.

  13. #13
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Which tabs library are you using for you tabs?
    Is it the one at this jQuery Tabs page?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  14. #14
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    If you are using the jQueryTools Tabs, then they are quite different.

    This should work for you with those ones:

    Code javascript:
    $("ul.tablink").tabs("div.panes > div", {event:'mouseover'});	
    $('.card_container').mouseleave(function () {
        $('ul.tablink', this).data('tabs').click(0);
    });

    More details can be found at the jQueryTools Scripting documentation page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  15. #15
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure if it is the same. There are 2 script files.

    tabs/tabs.js "jQuery Tools v1.2.5 - The missing UI library for the Web"

  16. #16
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, just noticed your other reply, will try that,

  17. #17
    SitePoint Evangelist
    Join Date
    Jan 2005
    Posts
    425
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks man, you are a champ! That works beautifully!

  18. #18
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by LuckyB View Post
    Thanks man, you are a champ! That works beautifully!
    Wonderful. It's just a matter of knowing what you're dealing with.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •