JS代码(随便放哪里):
<ภาษาสคริปต์ = "จาวาสคริปต์">
-
var flag=false;
ฟังก์ชั่น DrawImage (ImgD) {
var image=รูปภาพใหม่();
image.src=ImgD.src;
ถ้า(image.width>0 && image.height>0){
ธง=จริง;
ถ้า(image.width/image.height>= 180/110){
ถ้า(image.width>180){
ImgD.width=180;
ImgD.height=(image.height*110)/image.width;
}อื่น{
ImgD.width=image.width;
ImgD.height=image.height;
-
/*ImgD.alt="bigpic" */
-
อื่น{
ถ้า(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}อื่น{
ImgD.width=image.width;
ImgD.height=image.height;
-
/*ImgD.alt="bigpic" */
-
-
}
//-->
</สคริปต์>
ภาพที่使用的地方:
<img src="วอลล์เปเปอร์" border=0 width="180" height="110" onload="javascriptrawImage(this);">
width="180" height="110" 注意这里最好限定,如果不限定加载上时会成原大,然后再缩定,这个过程如果上了很难看的.这里是宽度和高度,在前的的JS里改,这里也作相应的改.
上不会变形,只会按比列缩,放heart