Jquery:当鼠标空闲时如何使某些东西淡出。当鼠标再次移动时,它会消失! [英] Jquery: how to make something fade out when mouse is idle. When mouse moves again, It fadesIn!

查看:202
本文介绍了Jquery:当鼠标空闲时如何使某些东西淡出。当鼠标再次移动时,它会消失!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为#top的div。当鼠标空闲 3秒钟时,我希望它淡出。当鼠标再次移动时,让它出现(当然是淡出)

I have a div called "#top". I would like it to fade out when the mouse is idle for 3 seconds. When the mouse moves again, make it appear (fade, of course)

有谁知道怎么做?

非常感谢。

推荐答案

使用 setTimeout ,将返回值保存在某处(使用 clearTimeout

var timer;
$(document).mousemove(function() {
    if (timer) {
        clearTimeout(timer);
        timer = 0;
    }

    $('#top:visible').fadeIn();
    timer = setTimeout(function() {
        $('#top').fadeOut()
    }, 3000)
})

你会想要这个 $(document).ready()等。

这篇关于Jquery:当鼠标空闲时如何使某些东西淡出。当鼠标再次移动时,它会消失!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆