CSS关于图片缩放和截取问题

来源:百度知道 编辑:UC知道 时间:2024/06/16 19:00:05
假如一张图片大小是300*400
我想先把他按比例缩放至150*200
然后再网页上只显示其中的150*100(截取其中一部分)
请问html和css里面分别如何定义?
谢谢了!

JS代码(随便放哪里):
<script language="javascript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 180/110){
if(image.width>180){
ImgD.width=180;
ImgD.height=(image.height*110)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt="bigpic" */
}
else{
if(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt="bigpic" */
}
}
}

//-->
</script>

图片使用的地方:
<img src="图片"