/* 计算图片 */ function autoSize(defwidth) { var img = $("#imgid"); var textWidth = $("#tbdiv").width(); var divHeight = $("#tbdiv").height(); if(textWidth <= defwidth) { img.width(textWidth*0.9-20); img.height("auto"); //console.log("----------"+img.height()/120); var raids = img.height()/120; if(raids > 1) { raids = 1; } var f1 = parseInt(32*raids); var f2 = parseInt(18*raids); //console.log("f1----------"+f1); //console.log("f2----------"+f2); // 字体调整 $("#wzdiv").css("font-size", f1+"px"); $("#wzydiv").css("font-size", f2+"px"); $("#wzya").css("font-size", f2+"px"); } else { img.width("auto"); img.height("auto"); } if(img.width() < 35) { // 设置最小值 img.width(35); img.height("auto"); // 字体调整 $("#wzdiv").css("font-size", "16px"); $("#wzydiv").css("font-size", "9px"); $("#wzya").css("font-size", "9px"); } else if(img.width() > 120) { // 设置最大值 img.width(120); img.height("auto"); // 字体调整 $("#wzdiv").css("font-size", "32px"); $("#wzydiv").css("font-size", "18px"); $("#wzya").css("font-size", "18px"); } img.css("margin-top", ((divHeight-img.height())/2)+"px"); img.css("margin-left", "0"); } /* 页面加载完成 */ $(document).ready(function() { autoSize(230); }); /* 窗口大小变化 */ $(window).resize(function() { autoSize(230); }).trigger("resize");