I've tried the below script to no avail. I have a series of tabs at www.1tryten.com. The tabs auto rotate and change on mouseover. I'm trying to have it so that the currently active tab sets the class for the body tag. Essentially, if tab-1 is active then the body class would be tab-1 etc. Is this doable.
$(document).ready(function() {
$("#tabs").tabs({
event: 'mouseover',
fx: {
opacity: 'toggle',
duration: 'slow',
show: function(event, ui) { $("body").addClass(ui.tab);}
}
}).tabs('rotate', 5000, true);
});
Here's the code for the tabs
<div id="tabs" class="tabs-bottom ui-tabs ui-widget ui-widget-content ui-corner-all">
<div id="tabsone" class="tabsone ui-tabs-panel ui-widget-content ui-corner-bottom" style="">
<img src="/images/mac-mini-banner.png">
<h3>Mac Mini Security Mount. New Mac Mini Mount.</h3>
</div>
<div id="tabstwo" class="tabstwo ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="">
<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.</开发者_如何学Pythonp>
</div>
<div id="tabsthree" class="tabsthree ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" style="">
<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>
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li id="tabone" class="tabsone ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tabsone"><img src="/images/laptop-lock-tab-nav.png"></a></li>
<li id="tabtwo" class="tabstwo ui-state-default ui-corner-top"><a href="#tabstwo"><img src="/images/computer-lock-tab-nav.png"></a></li>
<li id="tabthree" class="tabsthree ui-state-default ui-corner-top"><a href="#tabsthree"><img src="/images/locker-tab-nav.png"></a></li>
</ul>
</div>
Is this:
$("body").addClass(ui.tab);
trying to assign to body the classes of ui.tab? Because addClass expects a string as its parameter. What you should be doing is:
$("body").attr('class', $(ui.tab).attr('class'));
... assuming that ui.tab is a valid object.
Use the select callback:
$( ".selector" ).tabs({
select: function(event, ui) { ... }
});
--EDIT added code from website --
$("#tabs").tabs({
event: 'mouseover',
fx: {
opacity: 'toggle',
duration: 'slow'
},
show: function(event, ui) {
$("body").addClass(className);
}
});
A better explanation is here: http://www.springenwerk.com/2008/03/jquery-ui-tabs-callbacks.html
You can use the select event which gets triggered whenever you select any tab.
$(document).ready(function() {
$("#tabs").tabs({
event: 'mouseover',
fx: {
opacity: 'toggle',
duration: 'slow',
show: function(event, ui) { $("body").addClass(ui.tab);},
},
select: function(event, ui) { $("body").addClass($(ui.tab).attr('class'));}
}).tabs('rotate', 5000, true);
});
精彩评论