作者no1kk (心中在下雨)
看板Ajax
標題Re: [問題] jQuery width()
時間Thu Jul 7 01:08:12 2011
※ 引述《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
1F:推 Fantasywind:謝謝你!原來Image有預讀得功能 學了一課!! 07/07 04:33
2F:→ terrybob:學習了,感謝 07/07 13:37
3F:推 Luos:有沒有辦法對一個append的td用width()? 07/16 15:24