三个参数
<script type="text/javascript"> /* *sclass:设置包裹元素的类 * packages:设置包裹的元素 * row:设置每几个元素一组 * */ $('#iscroll>a').igroup({ sclass:'hi', packages:'li', row:3 }); </script>
代码
(function ( $ ) { var $iscroll=0; var $arr=new Array(); $.fn.igroup=function(options){ var settings = $.extend({ row:3, packages:'li', sclass:'scroll' }, options ); $olength= this.length; $last= this.eq($olength-1); if($olength%settings.row==0){ $count=$olength/settings.row-1; }else{ $count=$olength/settings.row; } for (var i=0; i <=$count; i++) { $last.after('<'+settings.packages+'>') }; $liall=this.nextAll(settings.packages); $c=0; $la=0; this.each(function(){ $liall.eq($c).append($(this)); $la++; if($la%settings.row==0&&$la!=0){ $c++ } }) $liall.addClass(settings.sclass); } }( jQuery ));