我有一个快速脚本,其轨迹跟随光标:
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()
});
我只是不知道当鼠标没有移动超过一秒钟时如何执行此操作。有任何想法吗?
谢谢,还有这是一个jsfiddle http://jsfiddle.net/wVVbT/5/
您添加一个在不活动一秒后触发的超时,并在鼠标在 1 秒内移动等情况下清除超时:
var timer;
$(document).on('mousemove', function(e){
clearTimeout(timer);
timer = setTimeout(function() {
$('.fall').fadeOut('slow', function() {
$(this).remove();
});
}, 1000);
});
FIDDLE http://jsfiddle.net/wVVbT/14/
EDIT:
我就是这样做的
FIDDLE http://jsfiddle.net/wVVbT/18/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)