图片等比缩放+局部放大+ThickBox
<html>
<head>
<title>标本资料</title>
<link href="css/Thickbox/thickbox.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript" src="js/thickbox.js"></script>
<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>
<script language="javascript" type="text/javascript">
var iDivHeight = 250; //放大显示区域宽度
var iDivWidth = 250;//放大显示区域高度
var iMultiple = 8; //放大倍数
//显示放大图,鼠标移动事件和鼠标点击事件都会调用本事件
//参数:src代表缩略图,sFileName放大图片名称
//原理:依据鼠标对应缩略图左上角(0,0)上的位置控制放大图左上角对应显示区域左上角(0,0)的位置
function show(src, sFileName)
{
//判断鼠标事件产生时是否同时按下了
if ((event.button == 1) && (event.ctrlKey == true))
iMultiple -= 1;
else
if (event.button == 1)
iMultiple += 1;
if (iMultiple < 2) iMultiple = 2;
if (iMultiple > 14) iMultiple = 14;
var iPosX, iPosY; //放大图对应显示区域左上角的坐标
var iMouseX = event.offsetX; //鼠标对应缩略图左上角的横坐标
var iMouseY = event.offsetY; //鼠标对应缩略图左上角的纵坐标
var iBigImgWidth = src.clientWidth * iMultiple; //放大图宽度,是缩略图的宽度乘以放大倍数
var iBigImgHeight = src.clientHeight * iMultiple; //放大图高度,是缩略图的高度乘以放大倍数
if (iBigImgWidth <= iDivWidth)
{
iPosX = (iDivWidth - iBigImgWidth) / 2;
}
else
{
if ((iMouseX * iMultiple) <= (iDivWidth / 2))
{
iPosX = 0;
}
else
{
if (((src.clientWidth - iMouseX) * iMultiple) <= (iDivWidth / 2))
{
iPosX = -(iBigImgWidth - iDivWidth);
}
else
{
iPosX = -(iMouseX * iMultiple - iDivWidth / 2);
}
}
}
if (iBigImgHeight <= iDivHeight)
{
iPosY = (iDivHeight - iBigImgHeight) / 2;
}
else
{
if ((iMouseY * iMultiple) <= (iDivHeight / 2))
{
iPosY = 0;
}
else
{
if (((src.clientHeight - iMouseY) * iMultiple) <= (iDivHeight / 2))
{
iPosY = -(iBigImgHeight - iDivHeight);
}
else
{
iPosY = -(iMouseY * iMultiple - iDivHeight / 2);
}
}
}
div1.style.height = iDivHeight;
div1.style.width = iDivWidth;
if (div1.innerHTML == "")
{
div1.innerHTML = "<img id=BigImg style='position:relative'>";
BigImg.src=sFileName;
}
BigImg.width = iBigImgWidth;
BigImg.height = iBigImgHeight;
BigImg.style.top = iPosY;
BigImg.style.left = iPosX;
}
</script>
</head>
<body>
<p></p>
<table cellspacing="0" cellpadding="1" width="727" align="center" border="0">
<tr>
<td align="center">
<table bordercolor="#000000" height="301" cellspacing="0" cellpadding="0" width="302"
bgcolor="#deffde" border="1">
<tr>
<td align="center">
<marquee scrolldelay="120" width="80%"><font size="2">将鼠标移入标本图中,右方显示局部放大图;单
击鼠标左键,可以增大放大倍数;鼠标单击时同时按Ctrl键则减小放大倍数。</font></marquee><br>
<img onmousemove="show(this, 'paimaizhibo/UploadFiles_4728/lnzz100110shuhua/177.jpg')" onmousedown="show(this, 'paimaizhibo/UploadFiles_4728/lnzz100110shuhua/177.jpg')"
id="imgSource" src="paimaizhibo/UploadFiles_4728/lnzz100110shuhua/177.jpg" onload="DrawImage(this,200,200)" />
</td>
</tr>
</table>
</td>
<td style="WIDTH: 15px" width="15"></td>
<td align="center">
<table bordercolor="#000000" height="301" cellspacing="0" cellpadding="0" width="302"
bgcolor="#deffde" border="1">
<tr>
<td align="center"><a href="paimaizhibo/UploadFiles_4728/lnzz100110shuhua/177.jpg"class="thickbox">打开原图</a>
<div id="div1" style="OVERFLOW: hidden">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
< </body></html>
浙公网安备 33010602011771号