本文主要是介绍一个图片局部放大镜,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
转自无忧脚本
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<title>标本资料</title>
<script language="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 = "http://biomuseum.zsu.edu.cn/ASP/search/hexapod/big_pic/" + 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="middle">
<table bordercolor="#000000" height="301" cellspacing="0" cellpadding="0" width="302" bgcolor="#deffde" border="1">
<tr>
<td align="middle">
<marquee scrolldelay="120" width="80%"><font size="2">将鼠标移入标本图中,右方显示局部放大图;单击鼠标左键,可以增大放大倍数;鼠标单击时同时按Ctrl键则减小放大倍数。</font></marquee><br>
<img οnmοusemοve="show(this, 'B-000002.jpg')" οnmοusedοwn="show(this, 'B-000002.jpg')" id="imgSource" src="http://biomuseum.zsu.edu.cn/ASP/search/hexapod/small_pic/B-000002.jpg">
</td>
</tr>
</table>
</td>
<td style="WIDTH: 15px" width="15"></td>
<td align="middle">
<table bordercolor="#000000" height="301" cellspacing="0" cellpadding="0" width="302" bgcolor="#deffde" border="1">
<tr>
<td align="middle"><a href="01/B-000002.jpg" target="_blank">打开原图</a>
<div id="div1" style="OVERFLOW: hidden">
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<p></p>
</body>
</html>
这篇关于一个图片局部放大镜的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!