我有一個快速的腳本,有一個線索跟隨光標:執行jQuery的,當鼠標停止移動
jQuery(document).ready(function(){
$(document).mousemove(function(e){
$('.fall').each(function(){
if ($(this).css("opacity") == 0){
$(this).remove();
};
});
t = (e.pageY - 10).toString() + 'px';
l = (e.pageX - 10).toString() + 'px';
$('.fall').css("margin_left",l);
$('.fall').css("margin_top",t);
var doit = '<div class="fall" style="position:fixed;margin-left:' + l + ';margin-top:' + t + ';">+</div>'
$('body').prepend(doit);
$('#status2').html(e.pageX +', '+ e.pageY);
$('.fall').animate({
marginTop: '+=50px',
opacity: 0
},1000);
});
});
現在我想刪除animate
一部分,並具有類似如下當鼠標不移動:
$('.fall').each(function(){
$(this).fadeOut('slow');
$(this).remove()
});
我只是無法弄清楚如何執行此,當鼠標不動的不是像第二更。有任何想法嗎?
更新會在每次移動和使用的setTimeout時間VAR'mouseLastMoved'檢查'現在> mouseLastMoved + X seconds'? – Popnoodles
我不太明白你想要什麼,但我更新它使用你的新代碼:http://jsfiddle.net/wVVbT/9/ - 這有幫助嗎? – Joe
當鼠標停止移動時,我需要該行來執行...因此,您剛纔發佈的更新後的代碼並不是我想要的 –