2016-04-05 19 views
1

Kullanıcı 1,5 saniye boyunca fare ile öğenin üzerine geldiğinde değerleri tercüme etmek istiyorum. Biraz jQuery işlevi yazdım ama 1.5 saniye sonra kullanıcının öğe üzerinde olup olmadığını nasıl doğrulayabildiğimi bilmiyorum.JS setTimeout olayı gecikmeden sonra alın

$(document).on('mouseover', '.search-translate', function(e) { 
    setTimeout(function() { translate(e, this); }, 1500); 
}); 

function translate(pEvent, pThis) 
{ 
    if(pEvent.currentTarget == ???.currentTarget) 
    { 
     $.ajax(.....); 
    } 
} 

Herhangi bir fikri olan var mı?

+5

... 'setTimeout (; .bind (bu) 1500 function() {(e, bu) çevirmek});' – Rayon

+1

yılında zaman aşımı İptal bir fare işleyicisi. – nnnnnn

+0

@nnnnnn İyi fikir, teşekkürler dostum! – Phil795

cevap

0

Kullanım Bu kod ön ....

+0

Zaman aşımını iptal etme seçeneği yoktur. Çalışma sonucumu gönderiyorum ... – Phil795

0

Ben setTimeout olayı mouseout eğer, setTimeout başlangıç ​​mouseover Eğer

$(document).on('mouseover', '.search-translate', function(e) { 
 
\t \t \t var obj=this; 
 
\t \t \t setTimeout(function() { translate(e, obj); }, 1500); 
 
\t \t }); 
 

 
\t \t function translate(pEvent, pThis) 
 
\t \t { 
 
\t \t \t alert(pEvent+" : "+pThis); 
 
\t \t }

iptal edilecektir. Sen setTimeout` `in` this` bağlam kaybediyor

var tTimeout; 

function translate(pEl) 
{ 
    ....  
} 

$(document).ready(function() { 
    $(document).on('mouseover', '.search-translate', function(e) { 
     var el = this; 

     tTimeout = setTimeout(function() { translate(el); }, 1500); 
}); 

$(document).on('mouseout', '.search-translate', function() { 
    clearTimeout(tTimeout); 
});