html 怎样在图片加载前定义大小

下载一定要设昵称 2009-09-21 09:58:08
我朋友的一个网站,遇到了点小问题,就是网速快的时候没什么影响,网速很慢的情况下网页里面的图片会把网页撑的很大,然后过会才恢复正常,我看了觉得应该是onload的问题,就是不知道怎么改,网站如下:
http://www.xihuituteng.cn/
下面是涉及到的源码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<Script language="javascript">
var flag=false;
function DrawImage(ImgD,ImgWidth,ImgHeight){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= ImgWidth/ImgHeight){
if(image.width>ImgWidth){
ImgD.width=ImgWidth;
ImgD.height=(image.height*ImgWidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>ImgHeight){
ImgD.height=ImgHeight;
ImgD.width=(image.width*ImgHeight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
</Script>
<head>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td width="33.3333333333333%" align="center"><table width="150" border="0" cellpadding="0" cellspacing="3" bgcolor="#4A4B4C">
<tr>
<td height="152" align="center"><a href='Prodetails.asp?ID=154' target='_blank'><img src='Uploads/2009-4-8-10181.jpg' border='0' onload='javascript:DrawImage(this,144,152);'></a></td>
</tr>
</table>
</table>
</body>
</html>
...全文
715 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
frankyhuang2010 2012-10-09
  • 打赏
  • 举报
回复
我的网站www.yunying001.com也是这样, 百度优化建议提示图片大小未作定义,影响速度, 怎么弄啊??
浴火_凤凰 2009-09-22
  • 打赏
  • 举报
回复
友情帮顶!!!
xinyung 2009-09-22
  • 打赏
  • 举报
回复
开始就直接设置图片的width和height,<img width=** height=**
toury 2009-09-22
  • 打赏
  • 举报
回复
把函数里的
var image=new Image();
image.src=ImgD.src;


函数下面的image直接用ImgD
  • 打赏
  • 举报
回复
额,改图片并非是我想要的答案
  • 打赏
  • 举报
回复
没有可用的答案。。。
  • 打赏
  • 举报
回复
自己顶
ziyuanxian 2009-09-21
  • 打赏
  • 举报
回复
你把图改小点不就得了

87,993

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧