<html>
<title></title>
<head></head>
<style>
.thumbnail{overflow:hidden;width:400px;height:240px;}
</style>
<script src="http://code.jquery.com/jquery-1.4.1.min.js"></script>
<script language="javascript">
$(function(){
/* 圖片不完全按比例自動縮小 by zwwooooo */
$('#content div.thumbnail img').each(function(){
var x = 400; //填入目標圖片寬度
var y = 240; //填入目標圖片高度
var w=$(this).width(), h=$(this).height();//獲取圖片寬度、高度
if (w > x) { //圖片寬度大於目標寬度時
var w_original=w, h_original=h;
h = h * (x / w); //根據目標寬度按比例算出高度
w = x; //寬度等於預定寬度
if (h < y) { //如果按比例縮小後的高度小於預定高度時
w = w_original * (y / h_original); //按目標高度重新計算寬度
h = y; //高度等於預定高度
}
}
$(this).attr({width:w,height:h});
});
});
</script>
<body>
<div id="content">
<div id="thumbnail" class="thumbnail" >
<img id="web" src="./midle.png"/>
</div>
</div>
</body>
</html>