没有为此脚本悬停淡出

时间:2015-08-29 14:32:50

标签: javascript css

此脚本使用id"#transoverlay"淡化div。 1.5秒后&然后在鼠标移动时将其淡入。当鼠标悬停在#transoverlay上然后在鼠标不再悬停时重新启动计数器时,我怎样才能使它不会褪色?

        $(function () {
            var timer;
            var fadeInBuffer = false;
            $(document).mousemove(function () {
                if (!fadeInBuffer) {
                    if (timer) {
                        console.log("clearTimer");
                        clearTimeout(timer);
                        timer = 0;
                    }

                        console.log("fadeIn");
                    $('#transoverlay').fadeIn();
                    $('html').css({
                        cursor: ''
                    });
                } else {
                    fadeInBuffer = false;
                }


                timer = setTimeout(function () {
                    console.log("fadeout");
                    $('#transoverlay').fadeOut()
                    $('html').css({
                        cursor: 'none'
                    });
                    fadeInBuffer = true;
                }, 1500)
            });
        });

1 个答案:

答案 0 :(得分:0)

您可以在jQuery中使用悬停功能:https://api.jquery.com/hover/