chelbeh
12/13/2017 - 2:42 PM

hover with delay

Наведение с задержкой

    jQuery.fn.hoverWithDelay = function (inCallback, outCallback, delay) {
        this.each(function (i, el) {
            var timer;
            $(this).hover(function () {
                timer = setTimeout(function () {
                    timer = null;
                    inCallback.call(el);
                }, delay);
            }, function () {
                if (timer) {
                    clearTimeout(timer);
                    timer = null;
                } else
                    outCallback.call(el);
            });
        });
    }