简单的放大缩小,显示坐标功能.
------------------------
演示代码:
------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<헤드>
<TITLE> 문서 </TITLE>
<스타일 유형="텍스트/css">
몸{
패딩 : 0px ;
여백 : 0px;
배경색 : #999999 ;
}
.DivMain {
위치 : 절대 ;
텍스트 정렬 : 가운데 ;
오버플로: 숨김;
}
.DivMenu {
위치 : 절대 ;
텍스트 정렬 : 왼쪽 ;
오버플로: 숨김;
}
.ImgMain {
위치 : 절대 ;
오버플로: 숨김;
테두리 : 0px ;
}
.TB메인 {
배경색 : #CCCCCC ;
패딩 : 0px ;
테두리 : 0px ;
Z-인덱스 : 99 ;
줄 높이 : 18px ;
}
.TB메뉴 {
배경색 : #FFCCCC ;
패딩 : 0px ;
테두리 : 0px ;
Z-인덱스 : 99 ;
색상: #000000 ;
}
.HrScroll {
여백 : 0px;
배경색 : #FFFFFF ;
패딩 : 0px ;
테두리 : 0px ;
Z-인덱스 : 99 ;
색상 : #000000 ;
테두리 간격 : 0px;
너비 : 160px ;
높이 : 10px ;
}
</style>
<SCRIPT LANGUAGE="자바스크립트">
<!--
var 원본 너비 ;
var 원본 높이 ;
var objDivMain ;
var objTbMain ;
var objImg ;
var ObjDrag ;
var objDivMenu ;
var objTbMemu ;
var objbtnImgInfo ;
var objDivFlag;
var objHrScroll;
var oRcts ;
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);
}
함수 setOriginal() {
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=null;
}
}
함수 fnZoomIn() {
objImg.style.zoom = parsFloat(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 = parsFloat(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=null;
}
}
함수 setDisplay() {
if(objImg.style.visibility == ""){
objImg.style.visibility = "숨김";
}
또 다른{
objImg.style.visibility = "";
}
}
함수 fnContextMenu() {
window.event.returnValue=false;
}
//-->
</SCRIPT>
</HEAD>
<BODY oncontextmenu="fnContextMenu()">
<양식 이름="fmImgZoom">
<TABLE 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="hide/view" onclick="setDisplay()">
<input id="btnImgInfo" size="50">
</TD>
</TR>
</TABLE>
<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">
<TABLE 클래스="TBMenu">
<TR>
<TD>10%</TD>
<TD><button id="HrScroll" class="HrScroll"><hr noshade></button> </TD>
<TD>1600%</TD>
</TR>
</TABLE>
</div>
<DIV ID="DivFlag" STYLE="위치:absolute;visibility:hidden;width:1px;height:10px;z-index:99" onmousedown="fnSlipMouseDown(this)" onmousemove="fnSlipMouseMove()" onmouseup=" fnSlipMouseUp()" onmouseover="this.style.cursor ='hand'" onmouseout="this.style.cursor=''">↑</DIV>
</form>
</BODY>
</HTML>