1 (function($){ 2 /* 3 裁切图片插件 4 默认调用为 5 $(document).clipImg(); 6 三个参数分别为element,最大宽度,最大高度 7 $(document).clipImg({ 8 dom:".clipI111mg", 9 maxWidth:\'22110\', 10 maxHeight:\'22110\' 11 }); 12 */ 13 $.fn.clipImg=function(opts){ 14 this.option = opts || { 15 dom:".clipImg", 16 maxWidth:\'220\', 17 maxHeight:\'220\' 18 }; 19 var maxWidth=this.option.maxWidth; 20 var maxHeight=this.option.maxHeight; 21 var dom=$(this.option.dom); 22 dom.find(\'li\').each(function(index, el) { 23 var width=$(this).find(\'img\').width(); 24 var height=$(this).find(\'img\').height(); 25 if(width>height){ 26 $(this).find(\'img\').css({height:maxHeight}); 27 } 28 else if(width<height){ 29 $(this).find(\'img\').css({width:maxWidth}); 30 } 31 else if(width==height){ 32 $(this).find(\'img\').css({height:maxHeight}); 33 $(this).find(\'img\').css({width:maxWidth}); 34 } 35 }); 36 }; 37 })(jQuery); 38 $(document).clipImg();