ๆไปฅๆๅฏซไบไธ้ปjQueryไพ้ฒๅ ต้ไปถไบๆ 。
็ฏไพHTML
Img Resize
jQuery code
/**
* ๆๅฎๅๅๅ็็ธฎๅๅ่ฝ
* ๅปบ็ซๆฅๆ:2010/03/26
* ไฝ่
:David
* Email chan15tw@gmail.com
*/
(function() {
// $w - ้ๅถๅฏฌๅบฆ
$.fn.dramaImgResize = function($w) {
return this.each(function() {
// ๆพๅบๆๅฎๅๅๆๆ็บๅ็็dom
$(this)
.find('img')
.each(function() {
// ่ฅ่ถ
้่ฆๅฎๅฏฌๅบฆ,ๅๅฐๅๅงๅฏฌๅบฆไปฅๅ็ธฎๅๅฏฌๅบฆ็ด้ๆผdataไธญ
if ($(this).width() > $w) {
// ๆฐ้ซๅบฆ
$newH = Math.ceil($(this).height() / $(this).width() * $w);
// ่ณฆไบ่ณ่จ:$oW = ๅๅงๅฏฌๅบฆ,$oH = ๅๅง้ซๅบฆ,$nW = ๆฐๅฏฌๅบฆ,$nH = ๆฐ้ซๅบฆ,$click = ๆฏๅฆ้ปๆ
$(this)
.data('imgInfo', {$oW: $(this).width(), $oH: $(this).height(), $nW: $w, $nH: $newH})
.data('click', false)
.width($w)
.height($newH);
// ่ฅๅๆฌๅฐฑๆ่ถ
้ฃ็ต,ๅไธๅ ไธๅ็ๆน่ฎๅคงๅฐๅ่ฝ
if ($(this).parent()[0].tagName.toLowerCase() != 'a') {
$(this)
.css('cursor', 'pointer')
.click(function() {
if (!$(this).data('click')) {
$(this).animate({width: $(this).data('imgInfo').$oW, height: $(this).data('imgInfo').$oH}, 'fast', function() {
$(this).data('click', true);
});
} else {
$(this).animate({width: $(this).data('imgInfo').$nW, height: $(this).data('imgInfo').$nH}, 'fast', function() {
$(this).data('click', false);
});
}
return false;
});
}
}
});
});
}
})(jQuery);
็ฏไพ็ถฒๅ:http://www.drama.com.tw/jquery/imgResize.html
JSไธ่ผ:http://www.drama.com.tw/jquery/js/jquery.dramaImgResize.js


































