看板 Ajax 關於我們 聯絡資訊
※ 引述《Fantasywind (Fantasywind)》之銘言: : $("img.textPic").each(function(){ : var max_w = parseInt($(this).parent().css('width').replace("px",'')) - 30; : var max_h = parseInt($(this).parent().css('height').replace("px",'')) - 250; var tmp = new Image(); tmp.src = $(this).attr('src'); : var div = max_w / max_h; var img = tmp.width / tmp.height; : if (div > img){ : $(this).width(max_w); : } else { : $(this).height(max_h); : } : }) 此外 max_w 和 max_h 怎不用 $(this).parent().width() 來取? $(this) 呼叫很多次 可以在一開始的時後先丟進一個變數,會比較好 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.85.195.120
Fantasywind:謝謝你!原來Image有預讀得功能 學了一課!! 07/07 04:33
terrybob:學習了,感謝 07/07 13:37
Luos:有沒有辦法對一個append的td用width()? 07/16 15:24