我这儿收藏了一点代码,虽说不能完全实现你的要求,但应该对你有帮助。<html><style>
DIV {cursor: hand}
</style><body style="font-family: verdana">
<H2>Simple Drag and Resize Example</h2>
<h4>Use alt-click to multi-select</h4><input type=button value="Moving, click to resize"
onclick="toggleMoveResize(this); return false"><div moveable=true style="position: absolute;
top: 150px; left: 100px;
width: 100px; height: 100px;
background-color: red;
border: solid 2px black">
Click and drag me
</div><div moveable=true style="position: absolute;
top: 150px; left: 250px;
width: 100px; height: 100px;
background-color: blue;
border: solid 2px black">
Click and drag me
</div><script language="JavaScript">
var activeElements = new Array();
var activeElementCount = 0;var lTop, lLeft;
var doMove = true;
var doResize = false;function toggleMoveResize(e) {
if (doMove) {
doMove = false;
doResize = true;
e.value = "Resizing, Click to Move";
} else {
doMove = true;
doResize = false;
e.value = "Moving, Click to Resize";
}
}function mousedown() {
var mp; mp = findMoveable(window.event.srcElement); if (!window.event.altKey) {
for (i=0; i<activeElementCount; i++) {
if (activeElements[i] != mp) {
activeElements[i].style.borderWidth = "2px";
}
}
if (mp) {
activeElements[0] = mp;
activeElementCount = 1;
mp.style.borderWidth = "4px";
} else {
activeElementCount = 0;
}
} else {
if (mp) {
if (mp.style.borderWidth != "4px") {
activeElements[activeElementCount] = mp;
activeElementCount++;
mp.style.borderWidth = "4px";
}
}
} window.status = activeElementCount; lLeft = window.event.x;
lTop = window.event.y;
}document.onmousedown = mousedown;function mousemove() {
var i, dLeft, dTop; if (window.event.button == 1) { sx = window.event.x;
sy = window.event.y; dLeft = sx - lLeft;
dTop = sy - lTop; for (i=0; i<activeElementCount; i++) {
if (doMove)
moveElement(activeElements[i], dLeft, dTop);
if (doResize)
resizeElement(activeElements[i], dLeft, dTop);
} lLeft = sx;
lTop = sy; return false;
}}function moveElement(mp, dLeft, dTop) {
var e
e = mp;
e.style.posTop += dTop;
e.style.posLeft += dLeft;
}function resizeElement(mp, dLeft, dTop) {
var e;
e = mp;
e.style.posHeight += dTop;
e.style.posWidth += dLeft;
}function findMoveable(e) {
if (e.moveable == 'true')
return e; if (e.tagName == "BODY")
return null; return findMoveable(e.parentElement);
}function findDefinedMoveable(e) {
if ((e.moveable == 'true') || (e.moveable == 'false'))
return e; if (e.tagName == "BODY")
return null; return findDefinedMoveable(e.parentElement);
}function rfalse() {
return false;
}document.onmousemove = mousemove;
document.onselectstart = rfalse;</script></body></html>
DIV {cursor: hand}
</style><body style="font-family: verdana">
<H2>Simple Drag and Resize Example</h2>
<h4>Use alt-click to multi-select</h4><input type=button value="Moving, click to resize"
onclick="toggleMoveResize(this); return false"><div moveable=true style="position: absolute;
top: 150px; left: 100px;
width: 100px; height: 100px;
background-color: red;
border: solid 2px black">
Click and drag me
</div><div moveable=true style="position: absolute;
top: 150px; left: 250px;
width: 100px; height: 100px;
background-color: blue;
border: solid 2px black">
Click and drag me
</div><script language="JavaScript">
var activeElements = new Array();
var activeElementCount = 0;var lTop, lLeft;
var doMove = true;
var doResize = false;function toggleMoveResize(e) {
if (doMove) {
doMove = false;
doResize = true;
e.value = "Resizing, Click to Move";
} else {
doMove = true;
doResize = false;
e.value = "Moving, Click to Resize";
}
}function mousedown() {
var mp; mp = findMoveable(window.event.srcElement); if (!window.event.altKey) {
for (i=0; i<activeElementCount; i++) {
if (activeElements[i] != mp) {
activeElements[i].style.borderWidth = "2px";
}
}
if (mp) {
activeElements[0] = mp;
activeElementCount = 1;
mp.style.borderWidth = "4px";
} else {
activeElementCount = 0;
}
} else {
if (mp) {
if (mp.style.borderWidth != "4px") {
activeElements[activeElementCount] = mp;
activeElementCount++;
mp.style.borderWidth = "4px";
}
}
} window.status = activeElementCount; lLeft = window.event.x;
lTop = window.event.y;
}document.onmousedown = mousedown;function mousemove() {
var i, dLeft, dTop; if (window.event.button == 1) { sx = window.event.x;
sy = window.event.y; dLeft = sx - lLeft;
dTop = sy - lTop; for (i=0; i<activeElementCount; i++) {
if (doMove)
moveElement(activeElements[i], dLeft, dTop);
if (doResize)
resizeElement(activeElements[i], dLeft, dTop);
} lLeft = sx;
lTop = sy; return false;
}}function moveElement(mp, dLeft, dTop) {
var e
e = mp;
e.style.posTop += dTop;
e.style.posLeft += dLeft;
}function resizeElement(mp, dLeft, dTop) {
var e;
e = mp;
e.style.posHeight += dTop;
e.style.posWidth += dLeft;
}function findMoveable(e) {
if (e.moveable == 'true')
return e; if (e.tagName == "BODY")
return null; return findMoveable(e.parentElement);
}function findDefinedMoveable(e) {
if ((e.moveable == 'true') || (e.moveable == 'false'))
return e; if (e.tagName == "BODY")
return null; return findDefinedMoveable(e.parentElement);
}function rfalse() {
return false;
}document.onmousemove = mousemove;
document.onselectstart = rfalse;</script></body></html>
<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.ZoomIn.disabled = false;
fmImgZoom.ZoomOut.disabled = false;
fmImgZoom.Original.disabled = false;
fmImgZoom.FitScreen.disabled = false;
fmImgZoom.btnView.disabled = false;
fmImgZoom.btnImgInfo.disabled = false;
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" onclick="fnZoomIn()" disabled>
<input type="button" name="ZoomOut" value="ZoomOut" onclick="fnZoomOut()" disabled>
<input type="button" name="Original" value="Original" onclick="setOriginal()" disabled>
<input type="button" name="FitScreen" value="FitScreen" onclick="setFitScreen()" disabled>
<input type="button" name="btnView" value="hide/view" onclick="setDisplay()" disabled>
<input id="btnImgInfo" size="50" disabled>
</TD>
</TR>
</TABLE>
<div id="divMain" class="DivMain" onmousedown="fnDivMouseDown()">
<img src="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"" onmousedown="fnMouseDown(this)" onmousemove="fnMouseMove()" onmouseup="fnMouseUp()" >
<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" onmousedown="fnSlipMouseDown(this)" onmousemove="fnSlipMouseMove()" onmouseup="fnSlipMouseUp()" onmouseover="this.style.cursor ='hand'" onmouseout="this.style.cursor=''">↑</DIV>
</form>
</BODY>
</HTML>
<head>
<title> 鼠標取框 </title>
<script language="JavaScript">
var x0;
var y0;
var select=false;function Conmousedown()
{
x0=document.body.scrollLeft+event.clientX;// 鼠?起始横坐?
y0=document.body.scrollTop+event.clientY;// 鼠?起始?坐?
select=true;
}function document.onmouseup()
{
//document.all.img1.click();
select=false;
}function document.onselectstart()
{
return false;
}function document.ondrag()
{
return false;
}function Conmousemove()
{
if (select)
{
dd.style.display='';// 如果鼠?已?正?移?,将??置?可?。
if(document.body.scrollLeft+event.clientX-x0>0) // 从左向右
{
dd.style.left=x0;
dd.style.width=document.body.scrollLeft+event.clientX-x0-2;
}
else // 从右向左
{
dd.style.left=document.body.scrollLeft+event.clientX;
dd.style.width=x0-(document.body.scrollLeft+event.clientX);
}
if (document.body.scrollTop+event.clientY-y0>0)// 从上向下
{
dd.style.top=y0;
dd.style.height=document.body.scrollTop+event.clientY-y0;
}
else// 从下向上
{
dd.style.top=document.body.scrollTop+event.clientY;
dd.style.height=y0-(document.body.scrollTop+event.clientY);
}
}
}
</script>
</head>
<body>
<form name="form1">
<table>
<tr>
<td onMouseMove="javascript:Conmousemove()" onMouseDown="JavaScript:Conmousedown();">
<input type="image" name="img1" id="img1" src="22.jpg" onclick="return false;">
</td>
</tr>
</table>
<!--table id="dd" style="position:absolute; width:0px; height:0px; z-index:99; border:1px RED Solid; display:none;">
<tr>
<td></td>
</tr>
</table-->
<div id="dd" style="position:absolute; width:0px; height:0px; z-index:99; border:1px RED Solid; display:none;"><div>
</form>
</body>
</html>
<head>
<title> dtksh </title>
<script>
<!--
function caption()
{
if(bobo.style.visibility=="hidden") {
bobo.style.visibility=""
sway.style.visibility=""
}
else{
bobo.style.visibility="hidden"
sway.style.visibility="hidden"
}
}
-->
</script>
</head>
<body>
<div id="bobo"
style="visibility:hidden;position:absolute;top:20;left:15;
width:190;height:35;background-color:rgb(62,174,128);
filter:alpha(opacity=60)">
</div>
<div id="sway"
style="visibility:hidden;color:rgb(177,63,174);position:absolute;top:20;
width:190;height:100;margin-top:5;margin-left:5;">
<p style="font-family:bailey;font-size:14pt;font-weight:bold;text-align:center">
Sports is wonderful!
</p>
</div>
<p> <img src="ss07049.jpg"
onmouseover="caption()"
onmouseout="caption()"> </p>
<P class="p2" style="color:red">请把您的鼠标移动到图片上,然后再把鼠标从图片上挪开。</p>
</body>
</html>
你看看这个对你有用吗