zoukankan      html  css  js  c++  java
  • jQuery – 鼠标经过(hover)事件的延时处理

    说到延时,离不开window下的setTimeout方法,本实例的jQuery方法的核心也是setTimeout。代码不长,完整如下:

    (function ($) {
                $.fn.hoverDelay = function (hoverEvent, outEvent) {
                    var hoverTimer, outTimer;
                    return $(this).each(function () {
                        $(this).hover(function () {
                            var t = this;
                            clearTimeout(outTimer);
                            hoverTimer = setTimeout(function () {
                                hoverEvent.call(t);
                            }, 200);
                        }, function () {
                            var t = this;
                            clearTimeout(hoverTimer);
                            outTimer = setTimeout(function () {
                                outEvent.call(t);
                            }, 200);
                        });
                    });
                }
            })(jQuery);

    基本上都是代码在撑页面,说点有用的东西吧。
    hoverDelay方法共四个参数,表示意思如下:

    hoverDuring       鼠标经过的延时时间
    outDuring          鼠标移出的延时时间
    hoverEvent        鼠标经过执行的方法
    outEvent         鼠标移出执行的方法

  • 相关阅读:
    冒泡排序
    pdo 单例类
    php 事物处理
    支付宝支付
    反向代理和负载均衡
    execl导出
    网络层
    OSI 7层 TCP/IP 4层 综合5层
    面试总结
    CMD AMD
  • 原文地址:https://www.cnblogs.com/yeminglong/p/5753339.html
Copyright © 2011-2022 走看看