簡體   English   中英

jQuery stop()在自定義函數上工作嗎?

[英]does jQuery stop() work on custom functions?

我為每個圖像制作了三個圖像作為工具提示。 我想在一定的時間間隔內顯示工具提示,例如,第一個工具提示顯示2秒鍾,第二個間隔,第二個工具提示淡入,依此類推。

例如,可以使用此功能完成

function cycle(id) {
    var nextId = (id == "block1") ? "block2": "block1";
    $("#" + id)
        .delay(shortIntervalTime)
        .fadeIn(500)
        .delay(longIntervalTime)
        .fadeOut(500, function() {cycle(nextId)});
}

現在,我想要的是在每幅圖像上發生亂接操作時停止循環功能,並顯示相應的工具提示。 當鼠標再次離開時,循環功能將觸發。

如果我正確理解所有內容,請嘗試使用此代碼。 如果您將鼠標懸停在圖像上,Tt將停止該過程,如果您離開該圖像,則將繼續該過程。 如果您實現自定義函數(如jquery的fadeOut(),slideIn(),...函數),則stop()函數將對自定義函數起作用。

  $('#' + id)
.fadeIn(500, function () {
   var img = $(this).find('img'),
       self = $(this),
       fadeOut = true;

   img.hover(function () {
                fadeOut = false;                    
            }, 
            function () {
                window.setTimeout(function () {
                    self.fadeOut(500);
                }, 2000);
            }
      );

    window.setTimeout(function () {
        if (fadeOut === false) {
            return;
        }
        self.fadeOut(500);
    }, 2000);
});​

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM