Re: [問題] jQuery width()
※ 引述《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
推
07/07 04:33, , 1F
07/07 04:33, 1F
→
07/07 13:37, , 2F
07/07 13:37, 2F
推
07/16 15:24, , 3F
07/16 15:24, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
Ajax 近期熱門文章
PTT數位生活區 即時熱門文章