javascript類比ACDSEE簡易功能

來源:互聯網
上載者:User

簡單的放大縮小,顯示座標功能。
-------------------------------------
示範代碼:
-------------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> Document </TITLE>
<style type="text/CSS">
body{
 padding : 0px ;
 margin : 0px;
 background-color : #999999 ;
}
.DivMain {
 position : absolute ;
 text-align : center ;
 overflow : hidden ;
}
.DivMenu {
 position : absolute ;
 text-align : left ;
 overflow : hidden ;
}
.ImgMain {
 position : absolute ;
 overflow : hidden ;
 border : 0px ;
}
.TBMain {
 background-color : #CCCCCC ;
 padding : 0px ;
 border : 0px ;
 z-index : 99 ;
 line-height : 18px ;
 
}
.TBMenu {
 background-color : #FFCCCC ;
 padding : 0px ;
 border : 0px ;
 z-index : 99 ;
 color: #000000 ;
 
}
.HrScroll {
 margin : 0px;
 background-color : #FFFFFF ;
 padding : 0px ;
 border : 0px ;
 z-index : 99 ;
 color : #000000 ;
 border-spacing : 0px;
 width : 160px ;
 height : 10px ;
}
</style>
<SCRIPT LANGUAGE="javascript">
<!--
 var originalWidth ;
 var originalHeight ;
 var objDivMain ;
 var objTbMain ;
 var objImg ;
 var ObjDrag ;
 var objDivMenu ;
 var objTbMemu ;
 var objbtnImgInfo ;
 var objDivFlag;
 var objHrScroll;
 var oRcts ;
 var oTextRange ; 
function 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");
 originalWidth = obj.width;
 originalHeight = obj.height;
 objImg.style.width = originalWidth;
 objImg.style.height = originalHeight;
 fmImgZoom.FitScreen.click();
}
function setFitScreen() {
 initImg(objImg);
}
function 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 = originalHeight;
 objImg.style.zoom = 1 ;
 objDivMain.style.width = intBodyWidth ;
 objDivMain.style.height = intBodyHeight - objTbMain.clientHeight;
 fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
function 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);
}
function 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) ;
}
function fnMouseDown(obj) {
 ObjDrag=obj;
 ObjDrag.setCapture();
 ObjDrag.l=event.x-ObjDrag.style.pixelLeft;
 ObjDrag.t=event.y-ObjDrag.style.pixelTop;
}
function 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);
 }
}
function fnMouseUp() {
 if(ObjDrag!=null) {
  ObjDrag.releaseCapture();
  ObjDrag=null;
 }
}
function fnZoomIn() {
 objImg.style.zoom = parseFloat(objImg.style.zoom) + 0.01 ;
 fnWritePos(objImg.style.left,objImg.style.top,objImg.style.zoom);
}
function 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);
 }
}
function 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 = "hidden";
  objDivFlag.style.visibility = "hidden";
 }
}
function fnWritePos(intLeft,intTop,intZoom) {
 objbtnImgInfo.innerText = " ImgLeft:" + intLeft + " ImgTop:" + intTop + " ImgZoom:" + intZoom ;
}
function fnSlipMouseDown(obj) {
 ObjDrag=obj;
 ObjDrag.setCapture();
 ObjDrag.l = event.x - ObjDrag.style.pixelLeft;
 ObjDrag.t = ObjDrag.style.pixelTop;
}
function 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);
 }
}
function fnSlipMouseUp() {
 if(ObjDrag!=null) {
  ObjDrag.releaseCapture();
  ObjDrag=null;
 }
}

function setDisplay() {
 if(objImg.style.visibility == ""){
  objImg.style.visibility = "hidden";
 }
 else{
  objImg.style.visibility = "";
 }
}
function fnContextMenu() {
 window.event.returnValue=false;
}
//-->
</SCRIPT>
</HEAD>
<BODY oncontextmenu="fnContextMenu()">
<form name="fmImgZoom">
<TABLE id="tbMain" class="TBMain">
<TR>
 <TD>
  <input type="button" name="ZoomIn" value="ZoomIn" >
  <input type="button" name="ZoomOut" value="ZoomOut" >
  <input type="button" name="Original" value="Original" >
  <input type="button" name="FitScreen" value="FitScreen" >
  <input type="button" name="btnView" value="hide/view" >
  <input id="btnImgInfo" size="50">
 </TD>
</TR>
</TABLE>
<div id="divMain" class="DivMain" ><img src="/UploadPic/2007-4/200741191914588.jpg" id="imgMain" class="imgMain" onmousemove="fnMouseMove()" ></div>
<div id="divMenu" class="DivMenu" style="visibility:hidden">
<TABLE class="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="position:absolute;visibility:hidden;width:1px;height:10px;z-index:99"  onmousemove="fnSlipMouseMove()" >↑</DIV>
</form>
</BODY>
</HTML>



相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

Starter Package

SSD Cloud server and data transfer for only $2.50 a month

Get Started >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。