简单的放大缩小,显示坐标功能。
-------------------------------------
演示代码:
-------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transisi//EN">
<HTML>
<KEPALA>
<TITLE> Dokumen </TITLE>
<gaya tipe="teks/css">
tubuh{
bantalan: 0px;
margin : 0 piksel;
warna latar belakang : #999999 ;
}
.DivMain {
posisi : mutlak ;
perataan teks: tengah;
meluap : tersembunyi;
}
.DivMenu {
posisi : mutlak ;
perataan teks: kiri;
meluap : tersembunyi;
}
.ImgMain {
posisi : mutlak ;
meluap : tersembunyi;
batas : 0px;
}
.TBMain {
warna latar belakang : #CCCCCC ;
bantalan: 0px;
batas : 0px;
indeks-z : 99 ;
tinggi garis : 18px ;
}
.TBMenu {
warna latar belakang : #FFCCCC ;
bantalan: 0px;
batas : 0px;
indeks-z : 99 ;
warna: #000000 ;
}
.HrScroll {
margin : 0 piksel;
warna latar : #FFFFFF ;
bantalan: 0px;
batas : 0px;
indeks-z : 99 ;
warna : #000000 ;
spasi batas : 0px;
lebar: 160 piksel;
tinggi: 10 piksel;
}
</gaya>
<BAHASA SKRIP="JavaScript">
<!--
var lebar asli;
var asliTinggi;
var objDivMain;
var objTbMain;
var objImg;
var ObjDrag;
var objDivMenu ;
var objTbMemu ;
var objbtnImgInfo;
var objDivFlag;
var objHrScroll;
var oRcts;
var oTextRange;
fungsi setInit(obj) {
objDivMain = dokumen.getElementById("divMain") ;
objTbMain = dokumen.getElementById("TbMain") ;
objDivMenu = dokumen.getElementById("DivMenu") ;
objTbMenu = dokumen.getElementById("TbMenu") ;
objImg = dokumen.getElementById("imgMain") ;
objbtnImgInfo = dokumen.getElementById("btnImgInfo") ;
objDivFlag = dokumen.getElementById("DivFlag");
objHrScroll = dokumen.getElementById("HrScroll");
lebar asli = obj.lebar;
originalHeight = objek.tinggi;
objImg.style.width = Lebar asli;
objImg.style.height = tinggi asli;
fmImgZoom.FitScreen.klik();
}
fungsi setFitScreen() {
initImg(objImg);
}
fungsi setAsli() {
var intBodyWidth;
var intBodyHeight;
intBodyWidth = dokumen.body.clientWidth ;
intBodyHeight = dokumen.body.clientHeight ;
objImg.style.kiri = 0 ;
objImg.style.top = 0 ;
objImg.style.width = Lebar asli;
objImg.style.height = tinggi asli;
objImg.style.zoom = 1 ;
objDivMain.style.width = intBodyWidth ;
objDivMain.style.height = intBodyHeight - objTbMain.clientHeight;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
fungsi initImg(objSaat Ini) {
var intBodyWidth;
var intBodyHeight;
intBodyWidth = dokumen.body.clientWidth ;
intBodyHeight = dokumen.body.clientHeight ;
objTbMain.style.top = 0;
objTbMain.style.height = 20;
objTbMain.style.width = intBodyWidth;
objDivMain.style.kiri = 0 ;
objDivMain.style.height = intBodyHeight - objTbMain.clientHeight;
objDivMain.style.width = intBodyWidth ;
initZoom(objSaat Ini);
}
fungsi 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.kiri = 0;
fnWritePos (obj.style.left,obj.style.top,obj.style.zoom) ;
}
fungsi fnMouseDown(obj) {
ObjDrag=obj;
ObjDrag.setCapture();
ObjDrag.l=event.x-ObjDrag.style.pixelLeft;
ObjDrag.t=event.y-ObjDrag.style.pixelTop;
}
fungsi fnMouseMove() {
if(ObjDrag!=null) {
ObjDrag.style.left = acara.x-ObjDrag.l;
ObjDrag.style.top = acara.y-ObjDrag.t;
fnWritePos(ObjDrag.style.left,ObjDrag.style.top,ObjDrag.style.zoom);
}
}
fungsi fnMouseUp() {
if(ObjDrag!=null) {
ObjDrag.releaseCapture();
ObjDrag=batal;
}
}
fungsi fnZoomIn() {
objImg.style.zoom = parseFloat(objImg.style.zoom) + 0,01 ;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
fungsi 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);
}
}
fungsi fnDivMouseDown() {
if ( event.button == 2 && event.srcElement.id != "imgMain") {
objDivMenu.style.top = acara.y;
objDivMenu.style.left = acara.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 = "tersembunyi";
objDivFlag.style.visibility = "tersembunyi";
}
}
fungsi fnWritePos(intLeft,intTop,intZoom) {
objbtnImgInfo.innerText = " ImgLeft:" + intLeft + " ImgTop:" + intTop + " ImgZoom:" + intZoom ;
}
fungsi fnSlipMouseDown(obj) {
ObjDrag=obj;
ObjDrag.setCapture();
ObjDrag.l = acara.x - ObjDrag.style.pixelLeft;
ObjDrag.t = ObjDrag.style.pixelTop;
}
fungsi fnSlipMouseMove() {
if(ObjDrag!=null) {
if(acara.x >= oRcts[0].kiri && acara.x <= oRcts[0].kanan ){
ObjDrag.style.left = acara.x - objDivFlag.offsetWidth / 2;
}
ObjDrag.t = ObjDrag.style.pixelTop;
var intCurrentPos = ObjDrag.style.pixelLeft - oRcts[0].kiri + objDivFlag.offsetWidth / 2;
var intPicZoom = intCurrentPos / 10;
objImg.style.zoom = intPicZoom;
fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
}
fungsi fnSlipMouseUp() {
if(ObjDrag!=null) {
ObjDrag.releaseCapture();
ObjDrag=batal;
}
}
fungsi setTampilan() {
if(objImg.style.visibilitas == ""){
objImg.style.visibility = "tersembunyi";
}
kalau tidak{
objImg.style.visibilitas = "";
}
}
fungsi fnContextMenu() {
window.event.returnValue=false;
}
//-->
</SKRIP>
</KEPALA>
<BODY oncontextmenu="fnContextMenu()">
<nama formulir="fmImgZoom">
<TABEL id="tbMain" class="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()">
<masukan id="btnImgInfo" ukuran="50">
</TD>
</TR>
</TABEL>
<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(ini)" onmousedown="fnMouseDown(ini)" onmousemove="fnMouseMove()" onmouseup="fnMouseUp()" ></div>
<div id="divMenu" class="DivMenu" style="visibilitas:tersembunyi">
<TABEL kelas="TBMenu">
<TR>
<TD>10%</TD>
<TD><button id="HrScroll" class="HrScroll"><hr noshade></button> </TD>
<TD>1600%</TD>
</TR>
</TABEL>
</div>
<DIV ID="DivFlag" STYLE="posisi:absolute;visibilitas:tersembunyi;lebar:1px;tinggi:10px;z-index:99" onmousedown="fnSlipMouseDown(ini)" onmousemove="fnSlipMouseMove()" onmouseup=" fnSlipMouseUp()" onmouseover="this.style.cursor ='hand'" onmouseout="this.style.cursor=''">↑</DIV>
</bentuk>
</BODI>
</HTML>