- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a >
- .box {
- display: table-cell;
- vertical-align:middle;
- text-align:center;
- *display: block;
- *font-size: 175px; /*高度/字体大小的比值为1.14*/
- *font-family:Arial;
- width:200px;
- height:200px;
- border: 1px solid #ccc;
- padding:3px;
- overflow:hidden; /*防止用js缩放时出现不及时*/
- }
- .box img{
- vertical-align:middle; border:0;
- }
- </style>
- <script language="javascript">
- var flag=false;
- function DrawImage(ImgD,w,h){
- var image=new Image();
- image.src=ImgD.src;
- if(image.width>0 && image.height>0){
- flag=true;
- if(image.width/image.height>= w/h){
- if(image.width>w){
- ImgD.width=w;
- ImgD.height=(image.height*w)/image.width;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- }else{
- if(image.height>h){
- ImgD.height=h;
- ImgD.width=(image.width*h)/image.height;
- }else{
- ImgD.width=image.width;
- ImgD.height=image.height;
- }
- }
- }
- }
- </script>
- </head>
- <body>
- <div class="box">
- <img src="<a href="http://img.bbs.163.com/new/20111012/photo/go/gogo911@vip.163.com/95ea49bc830405a6481faed4ba98b1b8.jpg">http://img.bbs.163.com/new/20111012/photo/go/gogo911@vip.163.com/95ea49bc830405a6481faed4ba98b1b8.jpg" onload="DrawImage(this,200,200);" />
- </div>
- <hr />
- <div class="box">
- <img src="<a href="http://img.bbs.163.com/new/20111012/photo/go/gogo911@vip.163.com/7f94f4d589c952dd6cc267da2d4cb80e.jpg">http://img.bbs.163.com/new/20111012/photo/go/gogo911@vip.163.com/7f94f4d589c952dd6cc267da2d4cb80e.jpg" onload="DrawImage(this,200,200);" />
- </div>
- </body>
- </html>
- //该片段来自于http://www.codesnippet.cn/detail/170120131716.html
来源: http://www.codesnippet.cn/detail/170120131716.html