简单的放大缩小,显示坐标功能。
------------------------------------------------
演示代码:
------------------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 过渡//EN">
<HTML>
<头>
<标题>文档</标题>
<样式类型=“文本/css”>
身体{
内边距:0px;
边距:0px;
背景颜色:#999999;
}
.DivMain {
位置:绝对;
文本对齐:居中;
溢出:隐藏;
}
.DivMenu {
位置:绝对;
文本对齐:左对齐;
溢出:隐藏;
}
.ImgMain {
位置:绝对;
溢出:隐藏;
边框:0px;
}
.TBMain {
背景颜色:#CCCCCC;
内边距:0px;
边框:0px;
z 指数:99;
行高:18px;
}
.TBMenu {
背景颜色:#FFCCCC;
内边距:0px;
边框:0px;
z 指数:99;
颜色:#000000;
}
.HrScroll {
边距:0px;
背景颜色:#FFFFFF;
内边距:0px;
边框:0px;
z 指数:99;
颜色:#000000;
边框间距:0px;
宽度:160 像素;
高度:10 像素;
}
</风格>
<脚本语言=“JavaScript”>
<!--
var 原始宽度;
var 原始高度;
var objDivMain ;
var objTbMain ;
var objImg;
var ObjDrag ;
var objDivMenu ;
var objTbMemu ;
var objbtnImgInfo ;
var objDivFlag;
var objHrScroll;
var 对象;
var oTextRange ;
函数 setInit(obj) {
objDivMain = document.getElementById("divMain") ;
objTbMain = document.getElementById("TbMain") ;
objDivMenu = document.getElementById("DivMenu") ;
objTbMenu = document.getElementById("TbMenu") ;
objImg = document.getElementById("imgMain") ;
objbtnImgInfo = document.getElementById("btnImgInfo") ;
objDivFlag = document.getElementById("DivFlag");
objHrScroll = document.getElementById("HrScroll");
原始宽度 = obj.宽度;
原始高度 = obj.高度;
objImg.style.width=originalWidth;
objImg.style.height = 原始高度;
fmImgZoom.FitScreen.click();
}
函数 setFitScreen() {
initImg(objImg);
}
函数设置原始(){
var intBodyWidth ;
var intBodyHeight ;
intBodyWidth = document.body.clientWidth ;
intBodyHeight = document.body.clientHeight ;
objImg.style.left = 0 ;
objImg.style.top = 0 ;
objImg.style.width=originalWidth;
objImg.style.height = 原始高度;
objImg.style.zoom = 1 ;
objDivMain.style.width = intBodyWidth ;
objDivMain.style.height = intBodyHeight - objTbMain.clientHeight;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
函数 initImg(objCurrent) {
var intBodyWidth ;
var intBodyHeight ;
intBodyWidth = document.body.clientWidth ;
intBodyHeight = document.body.clientHeight ;
objTbMain.style.top = 0;
objTbMain.style.height = 20;
objTbMain.style.width = intBodyWidth;
objDivMain.style.left = 0 ;
objDivMain.style.height = intBodyHeight - objTbMain.clientHeight;
objDivMain.style.width = intBodyWidth ;
initZoom(objCurrent);
}
函数 initZoom(obj){
var intObjWidth ;
var intObjHeight ;
var intDivHeight ;
var intZoomRatio ;
intDivHeight = objDivMain.style.pixelHeight;
intObjHeight = obj.style.pixelHeight;
intZoomRatio = intDivHeight / intObjHeight;
obj.style.zoom = intZoomRatio ;
obj.style.top = 0;
obj.style.left = 0;
fnWritePos (obj.style.left,obj.style.top,obj.style.zoom) ;
}
函数 fnMouseDown(obj) {
ObjDrag = obj;
ObjDrag.setCapture();
ObjDrag.l=event.x-ObjDrag.style.pixelLeft;
ObjDrag.t=event.y-ObjDrag.style.pixelTop;
}
函数 fnMouseMove() {
if(ObjDrag!=null) {
ObjDrag.style.left = event.x-ObjDrag.l;
ObjDrag.style.top = event.y-ObjDrag.t;
fnWritePos(ObjDrag.style.left,ObjDrag.style.top,ObjDrag.style.zoom);
}
}
函数 fnMouseUp() {
if(ObjDrag!=null) {
ObjDrag.releaseCapture();
ObjDrag=空;
}
}
函数 fnZoomIn() {
objImg.style.zoom = parseFloat(objImg.style.zoom) + 0.01 ;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
函数 fnZoomOut() {
if(objImg.style.zoom>0.01){
objImg.style.zoom = parseFloat(objImg.style.zoom) - 0.01 ;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
}
函数 fnDivMouseDown() {
if ( event.button == 2 && event.srcElement.id != "imgMain") {
objDivMenu.style.top = event.y;
objDivMenu.style.left = event.x;
objDivMenu.style.visibility = "";
oTextRange = objHrScroll.createTextRange() ;
oRcts = oTextRange.getClientRects();
oBndRct = objDivFlag.getBoundingClientRect();
objDivFlag.style.top = oRcts[0].top;
objDivFlag.style.left = oRcts[0].left + parseInt(objImg.style.zoom * 10) ;
objDivFlag.style.visibility = "";
}
if ( event.button == 1 && event.srcElement.id != "imgMain") {
objDivMenu.style.visibility = "隐藏";
objDivFlag.style.visibility = "隐藏";
}
}
函数 fnWritePos(intLeft,intTop,intZoom) {
objbtnImgInfo.innerText = " ImgLeft:" + intLeft + " ImgTop:" + intTop + " ImgZoom:" + intZoom ;
}
函数 fnSlipMouseDown(obj) {
ObjDrag=obj;
ObjDrag.setCapture();
ObjDrag.l = event.x - ObjDrag.style.pixelLeft;
ObjDrag.t = ObjDrag.style.pixelTop;
}
函数 fnSlipMouseMove() {
if(ObjDrag!=null) {
if(event.x >= oRcts[0].left && event.x <= oRcts[0].right ){
ObjDrag.style.left = event.x - objDivFlag.offsetWidth / 2;
}
ObjDrag.t = ObjDrag.style.pixelTop;
var intCurrentPos = ObjDrag.style.pixelLeft - oRcts[0].left + objDivFlag.offsetWidth / 2;
var intPicZoom = intCurrentPos / 10;
objImg.style.zoom = intPicZoom;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
}
函数 fnSlipMouseUp() {
if(ObjDrag!=null) {
ObjDrag.releaseCapture();
ObjDrag=空;
}
}
函数设置显示(){
if(objImg.style.visibility == ""){
objImg.style.visibility = "隐藏";
}
别的{
objImg.style.visibility = "";
}
}
函数 fnContextMenu() {
window.event.returnValue=false;
}
//-->
</脚本>
</头>
<BODY oncontextmenu="fnContextMenu()">
<表单名称=“fmImgZoom”>
<表id =“tbMain”类=“TBMain”>
<TR>
<TD>
<input type="button" name="ZoomIn" value="ZoomIn" onclick="fnZoomIn()">
<input type="button" name="ZoomOut" value="ZoomOut" onclick="fnZoomOut()">
<input type="button" name="Original" value="Original" onclick="setOriginal()">
<input type="button" name="FitScreen" value="FitScreen" onclick="setFitScreen()">
<input type="button" name="btnView" value="隐藏/视图" onclick="setDisplay()">
<输入id =“btnImgInfo”大小=“50”>
</TD>
</TR>
</表>
<div id="divMain" class="DivMain" onmousedown="fnDivMouseDown()"><img src="<A href="/u/info_img/2009-06/08/22.jpg" id="imgMain" class="imgMain" onload="setInit(this)" onmousedown="fnMouseDown(this)" onmousemove="fnMouseMove()" onmouseup="fnMouseUp()" ></div>
<div id="divMenu" class="DivMenu" style="visibility:hidden">
<表类=“TBMenu”>
<TR>
<TD>10%</TD>
<TD><button id="HrScroll" class="HrScroll"><hr noshade></button> </TD>
<TD>1600%</TD>
</TR>
</表>
</div>
<DIV ID="DivFlag" STYLE="位置:绝对;可见性:隐藏;宽度:1px;高度:10px;z-index:99" onmousedown="fnSlipMouseDown(this)" onmousemove="fnSlipMouseMove()" onmouseup=" fnSlipMouseUp()" onmouseover="this.style.cursor ='hand'" onmouseout="this.style.cursor=''">↑</DIV>
</形式>
</正文>
</HTML>