<input type="submit" style="width:100px; height:30px; border: #628BDA 1px solid;" onmouseover="this.style.background='url(1.jpg)'" value="登陆">如果1.jpg尺寸很大,这个按钮只能显示左上角区域。怎样做才能让它缩小显示在width:100px; height:30px;里呢???
调试欢乐多
下面是一个图片缩放的例子LZ参考一下:<script language="JavaScript" type="text/javascript">
function DrawImage(ImgD,FitWidth,FitHeight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
if(image.width/image.height>= FitWidth/FitHeight){
if(image.width>FitWidth){
ImgD.width=FitWidth;
ImgD.height=(image.height*FitWidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
} else{
if(image.height>FitHeight){
ImgD.height=FitHeight;
ImgD.width=(image.width*FitHeight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
}
}
}
</script>
按比例显示的调用:<img src="1.jpg" width="100px" height="30px" onload="javaScript:DrawImage(this,100,30);"><br>