简单jQuery相等列插件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了简单jQuery相等列插件相关的知识,希望对你有一定的参考价值。
A very simple plug-in I wrote to make x number of columns equal height. Looks for the column with the biggest height then sets the rest to the same. I'm sure it can be made cleaner, will look into that later.
/** * @projectDescription Simple Equal Columns * @author Matt Hobbs * @version 0.01 */ jQuery.fn.equalCols = function(){ //Array Sorter var sortNumber = function(a,b){return b - a;}; var heights = []; //Push each height into an array $(this).each(function(){ heights.push($(this).height()); }); heights.sort(sortNumber); var maxHeight = heights[0]; return this.each(function(){ //Set each column to the max height $(this).css({'height': maxHeight}); }); }; //Usage jQuery(function($){ //Select the columns that need to be equal e.g $('div.column').equalCols(); $('#col1,#col2,#col3').equalCols(); });
以上是关于简单jQuery相等列插件的主要内容,如果未能解决你的问题,请参考以下文章