zoukankan      html  css  js  c++  java
  • jQuery hover 延时显示$.fn.hoverDelay (fnOver, fnOut,timeIn,timeOut) ;

    先看jQuery hover源代码:


    -----------------------------------------

    (function($) {

        $.fn.hoverDelay = function(fnOver, fnOut,timeIn,timeOut) {

                    var timeIn = timeIn || 200,

                        timeOut = timeOut || 200,

                        fnOut = fnOut || fnOver;

                    var inTimer = [],outTimer=[];

                    

                return this.each(function(i) {

                    $(this).mouseenter(function() {

                            var that = this;

                            clearTimeout(outTimer[i]);

                            inTimer[i] = setTimeout(function() {

                                fnOver.apply(that);

                            }, timeIn);

                      }).mouseleave( function() {

                            var that = this;

                            clearTimeout(inTimer[i]);

                            outTimer[i] = setTimeout(function() {

                                fnOut.apply(that)

                            }, timeOut);

                     });

            })

        }; 

    })(jQuery);

    --------------------------------------------------

    实例:

    --------默认值-------

    $("li").hoverDelay(

      function () {

        $(this).addClass('green');

      }, 

      function () {

        $(this).removeClass('green');

      }

    );

    -------------------------------

    $("li").hoverDelay(

      function () {

        $(this).addClass('green');

      }, 

      function () {

        $(this).removeClass('green');

      },1000,500

    );

    如有错误欢迎指出,共同学习。

    完整测试用例下载:http://115.com/file/c2aun17s#hoverdalay.html

  • 相关阅读:
    UVA.12096 The SetStack Computer ( 好题 栈 STL混合应用)
    HDOJ(HDU).1412 {A} + {B} (STL SET)
    UVA.10474 Where is the Marble ( 排序 二分查找 )
    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)
    HDOJ(HDU).1166 敌兵布阵 (ST 单点更新 区间求和)
    17 西安
    17 沈阳
    13 南京
    10/11 作战会议
    2019牛客国庆集训派对day5
  • 原文地址:https://www.cnblogs.com/piuba/p/2818336.html
Copyright © 2011-2022 走看看