jQuery切换内容,多个活动条件

jQuery切换内容,多个活动条件,jquery,jquery-selectors,hidden,visible,Jquery,Jquery Selectors,Hidden,Visible,我希望能在内容切换方面得到一些帮助 我目前有两个切换内容的选项卡-一个必须在任何时候设置为焦点,当所选的.content drawer可见时,会附加一个活动类别 虽然我下面的工作在操作单个选项卡时起作用,但在状态之间切换时,活动状态不起作用,因为:可见条件在错误的时间触发 有人能给我指出正确的方向吗?这是我目前的工作 $('.content drawer').hide(); $('.tab')。单击(函数(){ var target=$(this.rel); $('.content drawer

我希望能在内容切换方面得到一些帮助

我目前有两个切换内容的选项卡-一个必须在任何时候设置为焦点,当所选的
.content drawer
可见时,会附加一个活动类别

虽然我下面的工作在操作单个选项卡时起作用,但在状态之间切换时,活动状态不起作用,因为:可见条件在错误的时间触发

有人能给我指出正确的方向吗?这是我目前的工作

$('.content drawer').hide();
$('.tab')。单击(函数(){
var target=$(this.rel);
$('.content drawer').not(target.slideUp();
target.delay(500.slideToggle();
$('.tabs>li.focus').removeClass('focus');
$(this.parent().addClass('active focus');
if($('.content drawer:visible').length){
$('.tabs>li.active').removeClass('active');
}
返回false;
});​
计算内容

信息内容

试试这段代码

    $('.content-drawer').hide();

$('.tab').click(function() {
    var $this = $(this);
    var target = $(this.rel);
    $this.closest('li').addClass('active focus');
    // Add the classes to the closest li of the clicked anchor
    $('.tab').not($this).closest('li').removeClass('active focus');
    // Remove the classes for the non-clicked items
    $('.content-drawer').not(target).slideUp();
    // Slideup the other contents
    target.delay(500).slideToggle();
    // Toggle the current content
    if (target.is(':visible')) {
        // Only if the target is visible remove the active class
        $this.closest('li').removeClass('active');
    } 
    return false;
});​

我不完全理解您的问题是什么,但我看到您在异步/回调方面有一些问题。为什么不使用
animate
及其
callback
函数(而不是delay,从api.jquery.com/delay/i上的注释可以看出这是可能的)?
    $('.content-drawer').hide();

$('.tab').click(function() {
    var $this = $(this);
    var target = $(this.rel);
    $this.closest('li').addClass('active focus');
    // Add the classes to the closest li of the clicked anchor
    $('.tab').not($this).closest('li').removeClass('active focus');
    // Remove the classes for the non-clicked items
    $('.content-drawer').not(target).slideUp();
    // Slideup the other contents
    target.delay(500).slideToggle();
    // Toggle the current content
    if (target.is(':visible')) {
        // Only if the target is visible remove the active class
        $this.closest('li').removeClass('active');
    } 
    return false;
});​