我的Blog我做主^_^

走向一条通往JAVA的不归路...

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  64 随笔 :: 68 文章 :: 77 评论 :: 0 Trackbacks
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<TITLE>JavaScript自动生成图片缩略图及预览图</TITLE>
<Script language="JavaScript">
<!--
//*******************************************
//**代码功能:自动将对象内所有图片按比例缩放*****
//**对象内所有图片及预览原图禁止右键功能*******
//**对象内所有经过缩小的图片在本窗口内预览原图**
//**作者:逍遥居士,时间:2006年12月14日*******
//**网址:http://www.iered.com****************
//**申明:可以转载,但请保留此版权信息**********
//*******************************************
function killErrors(){return true;} 
window.onerror = killErrors;
function getElementById(id)
  {
    if (typeof(id) != "string" || id == "") return null;
    if (document.getElementById) return document.getElementById(id);
    if (document.all) return document.all(id);
    try {return eval(id);} catch(e){ return null;}
  }
function getMousexy(x)
{if (document.layers) getMouseLoc;
  else if (document.all) getMouseLoc();
if (x) return mouseLocation.x;
  else return mouseLocation.y;
}
function Point(x,y) {  this.x = x; this.y = y; }
mouseLocation = new Point(-500,-500);
function getMouseLoc(e)
{if(!document.all)
  {mouseLocation.x = e.pageX;mouseLocation.y = e.pageY;}
  else
  {mouseLocation.x = event.x + document.body.scrollLeft;mouseLocation.y = event.y + document.body.scrollTop;}
  return true;
}
if(document.layers){document.captureEvents(Event.MOUSEMOVE); document.onMouseMove = getMouseLoc;}
//MouseXyEnd
function getImgName(ims)
{var reName;
if (ims.lastIndexOf("/")==-1) reName = "Error";
else reName = ims.substring(ims.lastIndexOf("/")+1);
return reName.toUpperCase();
}
function stopImg(){return false;}
function HiddenImg()
{getElementById("sImg").style.visibility="hidden";
getElementById("sImg").style.display="none";
}
function ShowImg()
{var Im = window.event.srcElement;
var iName=Im.name.split("_");
var iws=iName[0],ihs=parseInt(iName[1])+20;
getElementById("ImgName").innerHTML=getImgName(Im.src)+"&nbsp;";
getElementById("sImgs").src=Im.src;
getElementById("sImgs").alt=getImgName(Im.src);
getElementById("sImgs").width=iws;
getElementById("sImg").style.left=getMousexy(true)+"px";
getElementById("sImg").style.top=getMousexy(false)+"px";
getElementById("sImg").style.width=iws+"px";
getElementById("sImgs").height=ihs;
getElementById("sImg").style.height=ihs+"px";
getElementById("sImg").style.visibility="visible";
getElementById("sImg").style.display="block";
}
function FormatImg(divid,iw,ih)
{
  var Img,m,wh;
  m=getElementById(divid).getElementsByTagName("IMG");
  for (var i=0; i<m.length; i++)
  {Img=new Image(),Img.src=m[i].src;
 wh=Img.width/Img.height;
 m[i].name=m[i].id=Img.width+"_"+Img.height+"_"+i;
 m[i].style.cursor="hand";
 m[i].alt=unescape("%u70B9%u51FB%u770B%u5927%u56FE%uFF01");
  m.item(i).attachEvent("onclick", ShowImg);
  m.item(i).attachEvent("oncontextmenu", stopImg);
  m.item(i).attachEvent("onselectstart", stopImg);
  m.item(i).attachEvent("ondragstart", stopImg);
  if (Img.width>Img.height){
  if (Img.width>=iw){
  m[i].width=iw;
  m[i].height=parseInt(iw/wh);}
  }
  else{
  if (Img.height>=ih){
  m[i].width=parseInt(ih*wh);
  m[i].height=ih;}
  }
  }
}
document.writeln("<div id=\"sImg\" style=\"z-index: 9999; left: 20px; visibility: hidden; width: 180px; position: absolute; top: 50px; height: 80px;display:none;\" oncontextmenu=\"return false\" onselectstart=\"return false\" ondragstart=\"return false\">");
document.writeln("<TABLE style=\"width: 100%; position: absolute; height:100%;\" cellSpacing=\"2\" cellPadding=\"0\" border=\"1\" bgcolor=\"#009966\"><TBODY>");
document.writeln("<TR height=\"20\"><TD align=\"center\">");
document.writeln("<table style=\"width: 100%;height:100%;\" cellSpacing=\"0\" cellPadding=\"0\" border=\"0\"><tr><td align=\"left\">&nbsp;<a href=\"JavaScript:HiddenImg()\" style=\"color:#FFFFFF; font-weight:bold;text-decoration:none;font-size:12px;\">关闭窗口<\/a><\/td>");
document.writeln("<td align=\"right\" id=\"ImgName\" style=\"color:#FFFFFF; font-weight:bold;font-size:12px;\"><\/td><\/tr></table><\/TD><\/TR>");
document.writeln("<TR>");
document.writeln("<TD align=\"center\">");
document.writeln("<img alt=\"\" src=\"\" align=\"absmiddle\" id=\"sImgs\" border=\"0\"><\/TD><\/TR>");
document.writeln("<\/TBODY><\/TABLE><\/DIV>");
//-->
</Script></HEAD><BODY>
<div id="article">
<img src="http://www.iered.com/htmlweb/BeautifulGirl.JPG" border="0">
<BR>
<img src="http://www.iered.com/htmlweb/BeautifulGirl.JPG" border="0">
</div>
<Script language="JavaScript">
FormatImg('article',300,260);
//FormatImg(对象ID,允许图片的最大宽度,允许图片的最大高度);
//也可以<BODY onLoad="FormatImg('article',300,260)">
</Script><BR>
<a href="http://www.iered.com/htmlweb/FormatImg.html" target="_blank">查看代码演示</a>
</BODY></HTML>

posted on 2007-01-31 17:14 java_蝈蝈 阅读(4651) 评论(0)  编辑  收藏 所属分类: JAVASCRIPT

只有注册用户登录后才能发表评论。


网站导航: