专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Web前端

给元素平添resize事件

发布时间:2010-05-20 14:01:29 文章来源:www.iduyao.cn 采编人员:星星草
给元素添加resize事件
(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);


当浏览器窗口被调整到一个新的高度或宽度时,就会触发resize事件,这个事件在window上面触发,那么如何给div元素增加resize事件,监听div的高度或宽度的改变呢?
某位大神用jquery实现的方法,这样就可以 $('div').resize(fucntion(){ .. })直接使用了;
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: