我正在使用 jQuery Tabs UI 中的以下功能做几件事——根据数据属性更改图像、拉随机引用和折叠一些 div——所有这些都在 jQuery UI 选项卡中的选项卡更改上。我还在第一个函数中通过 CSS 更改布局。
问题是准备好的文档并没有真正起作用。如果我使用 #hash URL 从另一个页面返回 0 选项卡,则会跳过第一个绑定事件并且 CSS 不会更改。
有没有办法让 document.ready 真正起作用?并始终如一地进行 CSS 更改?
$(document).ready(function () {
$('#tabs').bind('tabsshow', function (event, ui) {
var $tabs = $("#tabs").tabs();
$('#wrapper').css('width', '586px'); //show certain CSS for the 0 tab
$('#wrapper').css('margin', '80px auto');
$('#col2, #footer, #headermain h1, .hide').css('display', 'none');
if (ui.index != 0) {
$('#wrapper').css('width', '875px'); //show certain CSS for all other tabs
$('#wrapper').css('margin', '15px auto');
$('#col2, #footer, #headermain h1, .hide').css('display', 'block');
}
});
$(function () { //tab change fx
$('#tabs').tabs({
fx: {
opacity: 'toggle'
},
select: function (event, ui) {
$(".entry-content").hide('fast'); //collapse any open divs in other tabs on tab change
$(".bkcontent").hide('fast');
$('div#quotescontainer').load('quotes.html', function () {
var $quotes = $(this).find('div.quote'); //pull a random quote for the sidebar
var n = $quotes.length; //on any tab change
var random = Math.floor(Math.random() * n);
$quotes.hide().eq(random).fadeIn();
});
var img = $(ui.panel).data("image");
$("#headerwrapper").animate({
opacity: 'toggle'
}, function () { //change header image to the
$(this).css("background-image", "url(" + img + ")") //data attr of the tabs div
.animate({
opacity: 'toggle'
});
});
}
});
});
});