【发布时间】:2013-06-22 15:53:02
【问题描述】:
我有一个快速脚本,它有一个跟随光标的轨迹:
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()
});
当鼠标超过一秒钟没有移动时,我只是不知道如何执行此操作。有什么想法吗?
【问题讨论】:
-
每次移动时更新一个 var
mouseLastMoved并使用 setTimeout 来检查now > mouseLastMoved + x seconds? -
我不太明白你想要什么,但我更新了它以使用你的新代码:jsfiddle.net/wVVbT/9 - 这有帮助吗?
-
我需要在鼠标停止移动时执行该行...所以您刚刚发布的更新代码不是我想要的
-
@RyanSaxe - 好的,这个怎么样:jsfiddle.net/wVVbT/13(注意:归功于 adeneo,我刚刚添加和删除了一些代码)
标签: javascript jquery mouseevent