Xling's Blog
Hutia's JS
有问题欢迎留言,哈哈
<html> <head> <title>Just Test</title> <style> body {width:95%; height:95%; overflow:auto; padding:10px; margin:0px; } </style> <script type="text/javascript" > function init(){ window.rect=document.createElement("DIV"); with(rect.style){ display="none"; position="absolute"; border="1px solid navy"; backgroundColor="#C0D8FF"; overflow="hidden"; filter="alpha(opacity=30)"; } rect.rt=new _rect(); document.body.appendChild(rect); document.body.onmousedown=function(e){ e=window.event?window.event:e; var x=e.x?e.x:e.pageX, y=e.y?e.y:e.pageY; if(document.body.setCapture)document.body.setCapture(); document.body.mousedown=true; rect.rt.setPosition(x,y); with(rect.style){ display="block"; left=x+"px"; top=y+"px"; width=0+"px"; height=0+"px"; } } document.body.onmousemove=function(e){ e=window.event?window.event:e; var x=e.x?e.x:e.pageX, y=e.y?e.y:e.pageY; if(!document.body.mousedown)return; rect.rt.setEndPosition(x,y); with(rect.style){ left=rect.rt.l()+"px"; top=rect.rt.t()+"px"; width=rect.rt.w()+"px"; height=rect.rt.h()+"px"; } } document.body.onlosecapture=document.body.onmouseup=function(){ if(document.body.releaseCapture)document.body.releaseCapture(); document.body.mousedown=false; rect.style.display="none"; } } window.onload=init; // ----------------------------- // Author: Hutia // Some Classes // ----------------------------- function _rect(x1,x2,y1,y2){ this.isRect=true; this.x1=(isNaN(x1)||x1==""||x1==null||x1==undefined)?0:x1; this.x2=(isNaN(x2)||x2==""||x2==null||x2==undefined)?0:x2; this.y1=(isNaN(y1)||y1==""||y1==null||y1==undefined)?0:y1; this.y2=(isNaN(y2)||y2==""||y2==null||y2==undefined)?0:y2; this.w=function(){return(Math.abs(this.x2-this.x1));} this.h=function(){return(Math.abs(this.y2-this.y1));} this.l=function(){return(Math.min(this.x2,this.x1));} this.t=function(){return(Math.min(this.y2,this.y1));} this.x=function(){return((this.x2+this.x1)/2);} this.y=function(){return((this.y2+this.y1)/2);} this.setLeft=function(numI){this.x1=numI;} this.setTop=function(numI){this.y1=numI;} this.setWidth=function(numI){this.x2=this.x1+numI;} this.setHeight=function(numI){this.y2=this.y1+numI;} this.setPosition=function(x,y){this.x1=x;this.y1=y;} this.setEndPosition=function(x,y){this.x2=x;this.y2=y;} this.setSize=function(w,h){this.x2=this.x1+w;this.y2=this.y1+h;} this.duplicate=function(){return(new _rect(this.x1,this.x2,this.y1,this.y2));} this.isCrossed=function(rect2){ if(!rect2)return;if(!rect2.isRect)return; var x01=this.l();var x02=x01+this.w(); var y01=this.t();var y02=y01+this.h(); var x11=rect2.l();var x12=x11+rect2.w(); var y11=rect2.t();var y02=y11+rect2.h(); if(x01<x11){ if(y01<y11)return(x02>x11&&y02>y11); if(y01>=y11&&y02<=y12)return(x02>x11); return(false); }else if(x01>=x11&&x01<=x12){ if(y01<y11)return(y02>y11); if(y01>=y11&&y02<=y12)return(true); return(false); } return(false); } } </script> </head> <body> <p> <h3>Author: Hutia</h3> <h5>Just For Fun</h5> Push mouse botton down then drag. </p> </body> </html> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
<script> // Author: Hutia // 转载请注明出处 var ss=new Array(); for(var i=0;i<20;i++)ss[i]=i; function as(){ return(Math.random()>0.5); } for(var j=0;j<10;j++){ for(var i=0;i<50;i++)ss=ss.sort(as); document.write(ss+"<br>"); } </script> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]