2016-02-22 187 views
-1

我已經有了一個我的貓頭鷹旋轉木馬的功能,它在當前滑塊可見時添加一個類「打開」,並在它不是時刪除。延遲功能removeClass

function syncPosition(el){ 

    var current = this.currentItem;  

    this.owl.owlItems.removeClass('turn-on'); 

    setTimeout(function() { 
    $(this).removeClass("turn-on"); 
    }, 2000); 

    $(this.owl.owlItems[this.owl.currentItem]).addClass('turn-on'); 

    } 

現在我需要爲removeClass添加2秒的延遲。 我試着用set-timeout,延遲但我做錯了,因爲它不起作用。

入住這fiddle

可能有人能幫我解決這個問題?

+0

的可能的複製[如何進行 「this」 關鍵字的工作?](http://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) – Teemu

回答

2

因爲this超時時間不同於syncPosition。 應該

​​
+0

但它仍然不起作用。我想要做的就是讓我的小提琴中的紅線(進度條)在最後可見2秒。 – Lukas