//缩放图片 function resizeimage( source_image , max_width , max_height){ var max_width = 100; var max_height = 100; var image = new image(); image.src = source_image.src; if (!max_width || parseint(max_width) <= 0){ max_width = max_width; } if (!max_height || parseint(max_height) <= 0){ max_height = max_height; } if(image.width > 0 && image.height > 0 ){ var image_rate = 1; if( (max_width / image.width) < (max_height / image.height)){ image_rate = max_width / image.width ; }else{ image_rate = max_height / image.height ; } if ( image_rate <= 1){ source_image.width = image.width * image_rate; source_image.height = image.height * image_rate; } } } $( function() { $(".picauto").each( function() { var boxwidth = $(this).attr("width"),boxheight = $(this).attr("height"); boxwidth = boxwidth?boxwidth:$(this).attr("_width"); boxheight = boxheight?boxheight:$(this).attr("_height"); var img = new image(),_this = $(this); img.src = $(this).attr("src"); /* if ( img.complete ) { var realwidth = img.width,realheight = img.height,padding = 0; if( realwidth boxwidth / boxheight ) { realheight = parseint( boxwidth / realwidth * realheight ); realwidth = parseint( boxwidth ); padding = parseint( ( boxheight - realheight ) / 2 ); _this.attr("width",realwidth).attr("height",realheight).css("padding",padding + "px 0"); } else { realwidth = parseint( boxheight / realheight * realwidth ); realheight = parseint( boxheight ); padding = parseint( ( boxwidth - realwidth ) / 2 ); _this.attr("width",realwidth).attr("height",realheight).css("padding","0 " + padding + "px"); } } }*/ img.onload = function() { var realwidth = img.width,realheight = img.height,padding = 0; if( realwidth boxwidth / boxheight ) { realheight = parseint( boxwidth / realwidth * realheight ); realwidth = parseint( boxwidth ); padding = parseint( ( boxheight - realheight ) / 2 ); _this.attr("width",realwidth).attr("height",realheight).css("padding",padding + "px 0"); } else { realwidth = parseint( boxheight / realheight * realwidth ); realheight = parseint( boxheight ); padding = parseint( ( boxwidth - realwidth ) / 2 ); _this.attr("width",realwidth).attr("height",realheight).css("padding","0 " + padding + "px"); } } return; }; } ); }); //---------- 内页图片自动缩放 $( function() { $(".picload").hide().each( function() { var img = new image(),_this = $(this),maxwidth = parseint( $(this).attr("maxwidth") ),showtime = $(this).attr("showtime"); img.src = $(this).attr("src"); if ( /^[0-9]+$/.test(showtime) ) { showtime = parseint(showtime); } if ( img.complete ) { if ( maxwidth > img.width ) { maxwidth = img.width; } $(this).attr("width",maxwidth).show(showtime); } img.onload = function() { if ( maxwidth > this.width ) { maxwidth = this.width; } _this.attr("width",maxwidth).show(showtime); return; }; } ); } ); document.writeln("")