jquery扩展

作者: wppeng | 来源:发表于2018-05-15 15:27 被阅读0次
  • 监听div大小改变事件
//监听div大小变化
(function($, h, c) {
    var a = $([]),
    e = $.resize = $.extend($.resize, {}),
    i,
    k = "setTimeout",
    j = "resize",
    d = j + "-special-event",
    b = "delay",
    f = "throttleWindow";
    e[b] = 250;
    e[f] = true;
    $.event.special[j] = {
        setup: function() {
            if (!e[f] && this[k]) {
                return false;
            }
            var l = $(this);
            a = a.add(l);
            $.data(this, d, {
                w: l.width(),
                h: l.height()
            });
            if (a.length === 1) {
                g();
            }
        },
        teardown: function() {
            if (!e[f] && this[k]) {
                return false;
            }
            var l = $(this);
            a = a.not(l);
            l.removeData(d);
            if (!a.length) {
                clearTimeout(i);
            }
        },
        add: function(l) {
            if (!e[f] && this[k]) {
                return false;
            }
            var n;
            function m(s, o, p) {
                var q = $(this),
                r = $.data(this, d);
                r.w = o !== c ? o: q.width();
                r.h = p !== c ? p: q.height();
                n.apply(this, arguments);
            }
            if ($.isFunction(l)) {
                n = l;
                return m;
            } else {
                n = l.handler;
                l.handler = m;
            }
        }
    };
    function g() {
        i = h[k](function() {
            a.each(function() {
                var n = $(this),
                m = n.width(),
                l = n.height(),
                o = $.data(this, d);
                if (m !== o.w || l !== o.h) {
                    n.trigger(j, [o.w = m, o.h = l]);
                }
            });
            g();
        },
        e[b]);
    }
})(jQuery, this);
//调用方法
$("#main").resize(function(){
    //当id为main的div大小变化时的处理函数写在这里.....
    //当然了#main只不过是id选择器,你也可以换成任何jquery的选择器......
});

相关文章

  • jQuery.extend 函数使用详解

    jQuery.extend 函数使用详解 JQuery的extend扩展方法:Jquery的扩展方法extend是...

  • $ 与extend

    原文: jQuery.extend 函数使用详解 JQuery的extend扩展方法:Jquery的扩展方法ext...

  • JQuery写拓展

    基础 $.extend()扩展JQuery静态方法,$.fn.extend()扩展JQuery实例方法静态方法: ...

  • jQuery扩展方法、自定义函数

    jQuery 应用扩展 (jQuery.extend({ myMethod: function () { ...

  • [jQuery] jQuery内核

    (1)创建全局jQuery对象 (2)扩展jQuery.prototype,然后调用

  • jquery扩展

    监听div大小改变事件

  • jQuery扩展

    jQuery.extend: 1、对象合并:将后面所有对象的值,覆盖在第一个对象上。(不适用于数组) 2、深度拷贝...

  • jQuery.extend 函数使用详解

    JQuery的extend扩展方法:Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一...

  • jQuery扩展插件

    什么是jQuery插件? 扩展jQuery原型对象的一个方法(jQuery插件是jQuery对象的一个方法)jQu...

  • jQuery

    插件开发 $.extend扩展jQuery方法,$.myFun()$.fn向jQuery添加新方法,$("#myD...

网友评论

    本文标题:jquery扩展

    本文链接:https://www.haomeiwen.com/subject/ztzirftx.html