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:

<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:


$("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

This might do the trick:


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

Edit:

Not quite - see below

Thanks, but nope, the tabs and panes completely disappear. “display: none”

Please link to a test page, so that we can help you further.

Ok, will try. This is on a development environment, and not live.

Will see what I can do.

Hi, please see here:
Tabs test

Many thanks

I have to go now, but it’s the select method (not selected) that you’ll see at the tabs methods documentation.

Thanks. I had tried that too, and couldn’t get it to work with:
$(this).tabs(“select”,1); (or 0)

Any more suggestions?

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

Well if it helps, this simple test page provides a working demonstration of the technique you want to apply.


<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>

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.

Which tabs library are you using for you tabs?
Is it the one at this jQuery Tabs page?

If you are using the jQueryTools Tabs, then they are quite different.

This should work for you with those ones:


$("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.

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”

Sorry, just noticed your other reply, will try that,

Thanks man, you are a champ! That works beautifully!

Wonderful. It’s just a matter of knowing what you’re dealing with. :slight_smile: