获取指定元素的最大子元素(包括自身)的width值和height值

来源:互联网 发布:淘宝卖家中心手机 编辑:程序博客网 时间:2024/05/23 11:49
/* * 返回该htmlEl的最大子元素(包括自身)的width值 */getMaxWidth : function(htmlEl, includeSelf) {var self = this;if(htmlEl) {var children = $(htmlEl).children(),maxWidth = includeSelf ? $(htmlEl).width() : 0;hx.each(children, function(item){var curWidth;// width()等于0的情况是,用户没有指定其widthcurWidth = (0===$(item).width() ? this.getMaxWidth(item) : $(item).width());maxWidth = (curWidth > maxWidth) ? curWidth : maxWidth;}, self);return maxWidth;} else {return 0;}}

/* * 返回该htmlEl的最大子元素(包括自身)的height值 */getMaxHeight : function(htmlEl, includeSelf) {var self = this;if(htmlEl) {var children = $(htmlEl).children(),maxHeight = includeSelf ? $(htmlEl).height() : 0;hx.each(children, function(item){var curHeight;// height()等于0的情况是,用户没有指定其heightcurHeight = (0===$(item).height() ? this.getMaxHeight(item) : $(item).height());maxHeight = (curHeight > maxHeight) ? curHeight : maxWidth;}, self);return maxHeight;} else {return 0;}}


原创粉丝点击