2010-07-05 32 views
2

我試圖通過單擊我的頁眉中的幫助鏈接來實現可以打開和關閉的幫助圖層。JQuery的切換幫助圖層qTip:beforeShow問題

我知道qTip無法做一些身體懸停技巧或類似的東西,因此我認爲最簡單的事情就是使用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() 
}); 

謝謝!!

回答

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並不是非常明顯。

希望這可以幫助別人。乾杯。