2

我正在尝试实现一个帮助层,可以通过单击页面标题中的帮助链接来打开和关闭。

我知道 qTip 不能针对 live() 选择器而不做一些身体悬停技巧或类似的事情,所以我认为最简单的事情是使用 beforeShow 回调来测试身体是否应用了“帮助”类或不。不幸的是,当我使用警报进行测试时,似乎 beforeShow 函数只是在页面加载时被调用,而不是像预期的那样实际上是“显示前”。有人有任何见解或类似的过去经历吗?

// outside of document ready function

function checkHelpLayerStatus() {
    alert('things that make you go hmmmmm');
    if ($('body').hasClass('help')) { 
    }
    else {
        $('.tip').qtip({disable: true});
    }
}

// inside document ready function

$("#header a:contains(Help)").click(function(e) {
    $('body').toggleClass('help');
    e.preventDefault();
});

$("body th:contains(Test Tip)").addClass('tip').qtip({
    content: 'This is an active list element',
    beforeShow: checkHelpLayerStatus()
});

谢谢!!

4

1 回答 1

1

感谢您的更正,马塞尔。顺便说一句,当我只是想在发布之前有趣地改变我的代码时,我犯了这个错误,在这里。它与问题无关。

如果其他人在使用 qTip api 时遇到问题,这里是解决方案。

// Help Layer
$("#help").click(function(e) {
    $('body').toggleClass('help');
    e.preventDefault();
});

$("body th:contains(Help Test)").addClass('tip').qtip({
    content: {
        text: 'Help Layer Is On'
    },
    api: {
        beforeShow: checkHelpLayerStatus
    }
});

function checkHelpLayerStatus() {
    if ($('body').hasClass('help')) { 
    }
    else {
        return false
    }
}

具体来说,回调必须包含在 api: {} 括号中,从文档中看,IMO 并不是很明显。

希望这可以帮助别人。干杯。

于 2010-07-06T14:50:40.003 回答