Rya*_*axe 11 javascript jquery mouseevent
我有一个快速脚本,跟随光标有一个跟踪:
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);
});
});
Run Code Online (Sandbox Code Playgroud)
现在我想移除animate部件,并在鼠标不移动时使用以下内容:
$('.fall').each(function(){
$(this).fadeOut('slow');
$(this).remove()
});
Run Code Online (Sandbox Code Playgroud)
当鼠标移动速度超过一秒钟时,我无法弄清楚如何执行此操作.有任何想法吗?
谢谢,这是一个jsfiddle
ade*_*neo 13
添加一秒钟不活动后触发的超时,如果鼠标在1秒内移动则清除超时等:
var timer;
$(document).on('mousemove', function(e){
clearTimeout(timer);
timer = setTimeout(function() {
$('.fall').fadeOut('slow', function() {
$(this).remove();
});
}, 1000);
});
Run Code Online (Sandbox Code Playgroud)
编辑:
这是我怎么做的
这是你需要的吗?的jsfiddle
lastTimeMouseMoved = new Date().getTime();
var t = setTimeout(function() {
var currentTime = new Date().getTime();
if (currentTime - lastTimeMouseMoved > 1000) {
$('.fall').fadeOut('slow');
// $('.fall').remove();
}
}, 1000)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11035 次 |
| 最近记录: |