1
我有這段代碼來顯示我創建的工具提示。它顯示在鼠標懸停,延遲2秒後。
/* Custom Shop Page Toolip */
var timeout;
$('.product-bottom-info-container').hover(
var that = this;
function(e) {
timeout = setTimeout(function() {
that.find('.product-custom-tooltip-container').css({
display: 'inline-block',
position: 'fixed',
zIndex: '5000',
margin: '10px',
whiteSpace: "nowrap"
}).position({
my: "right top",
at: "left bottom",
of: e,
collision: "fit"
});
}, 2000);
},
function() {
clearTimeout(timeout);
that.find('.product-custom-tooltip-container').hide();
}
);
調用setTimeout()
後,我不再能夠訪問$(this)
,這是引用。產品底部-信息容器選擇。
所以我試圖創建一個變量,而不是 - var that = $(this)
。我在該行發現錯誤意外令牌var。我也嘗試過var that = this
,這也行不通。
如何在setTimeout()
函數中訪問$(this)
?
我一直在閱讀各種各樣的例子,namely this one,它似乎適用於某些,但它不適合我。
不知道爲什麼投票,爲我工作。非常感謝 – anthonyCam
@ItsMeMike我已經更新了更改。請看看它。 ':''不要忘記在10分鐘內接受我的回答。 –
當然,再次感謝。有用的信息 – anthonyCam