用JS模拟Window下的拖选界面.

下面IMG标签中有一个图片,大家可以自己找一个,这个图片就是拖选时的选框.图片最好是方形的,有10个像素就可以了.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0037)http://www.pniu.net/test/dragbox.html -->
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<META content="MSHTML 6.00.3790.0" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff><IMG id=selectBox
style="BORDER-RIGHT: blue 1px solid; BORDER-TOP: blue 1px solid; DISPLAY: none; Z-INDEX: 500; FILTER: alpha(opacity=50); LEFT: 0px; BORDER-LEFT: blue 1px solid; WIDTH: 0px; BORDER-BOTTOM: blue 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: 0px"
src="dragbox_files/box.bmp">
<SCRIPT language=JScript>
document.οnmοusedοwn=foo1;
document.οnmοusemοve=foo2;
document.οnmοuseup=foo3;
var mousedown=false;
var x1,y1,x2,y2;
function foo1(){
mousedown=true;
x1=event.x+document.body.scrollLeft;
y1=event.y+document.body.scrollTop;
}
function foo2(){
x2=event.x+document.body.scrollLeft;
y2=event.y+document.body.scrollTop;
if(mousedown){
selectBox.style.display="";
selectBox.style.width=1;
selectBox.style.height=1;
if(x1<x2&&y1==y2){
selectBox.style.top=y1;
selectBox.style.left=x1;
}
if(x1>x2&&y1==y2){
selectBox.style.top=y1;
selectBox.style.left=x2;
}
if(x1==x2&&y1>y2){
selectBox.style.top=y2;
selectBox.style.left=x1;
}
if(x1==x2&&y1<y2){
selectBox.style.top=y1;
selectBox.style.left=x1;
}
if(x1>x2&&y1>y2){
selectBox.style.top=y2;
selectBox.style.left=x2;
}
if(x1<x2&&y1<y2){
selectBox.style.top=y1;
selectBox.style.left=x1;
}
if(x1<x2&&y1>y2){
selectBox.style.top=y2;
selectBox.style.left=x1;
}
if(x1>x2&&y1<y2){
selectBox.style.top=y1;
selectBox.style.left=x2;
}
selectBox.style.width=Math.abs(x1-x2);
selectBox.style.height=Math.abs(y1-y2);
}
}
function foo3(){
selectBox.style.display="none";
mousedown=false;
}
function avoid(){
event.returnValue=false;
event.cancelBubble=true;
}
document.onselectstart=avoid;
</SCRIPT>
 
<DIV></DIV><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR>
<BR>
<BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR></BODY></HTML>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值