作者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