⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 drag.js

📁 无刷新技术AJAX,就是在不刷新网页的情况下更新网站内容
💻 JS
字号:
//Code by Jarry.Li ,CopyRight @ Jiarry.126.com,All right reserved !
//homepage : http://Jiarry.blogchina.com  
//E-mail:jiarry@hotmail.com
//使用方法:
/**************
<div id="confirm" 
style="display:none;width:200px;height:100px;background-color:#77c;z-index:11;position:absolute;text-align:center;" 
rel="drag"
onmousedown="dargit(this,event);
">
</div>
**************/

var ey=0,ex=0,lx=0,ly=0,canDrg=false,thiso=null;//
var x, y,rw,rh;
	var divs=document.getElementsByTagName("div");
	for (var i=0;i<divs.length;i++){	
	  if(divs[i].getAttribute("rel")=="drag"){
	    divs[i].onmousemove=function(){
		   thismove(this);//实时得到当前对象与鼠标的值以判断拖动及关闭区域;
		}
	  }
	}

function thismove(o){
    rw=parseInt(x)-parseInt(o.style.left);
    rh=parseInt(y)-parseInt(o.style.top);
	//document.title=rw+"=文本区域="+rh;
    if(rh<=20 && rw>=180);//document.title=rw+"||20*20||"+rh;//右上角20*20的关闭区域
	if(rh<=20 && rw<180 );//document.title=rw+"||可选||"+rh;//绝对拖动条选择区域;
}
function dargit(o,e){
thiso = o;
canDrg = true;
 if(!document.all){
      lx = e.clientX; ly = e.clientY;
      }else{
        lx = event.x; ly = event.y;
	  }
 if(document.all) thiso.setCapture();
 
 try{//设置渐变色;

  if(rh<=20 && rw<180 ){//设定在拖动区域
  if(document.all)thiso.filters.Alpha.opacity=50;
  else thiso.style.MozOpacity=50/100;
  }

}catch(e){
 // alert(e.toString());
}
	st(o);//置前或置后
 
}

document.onmousemove = function(e){
if(!document.all){ x = e.clientX; y = e.clientY; }else{ x = event.x; y = event.y; }
if(canDrg){
  if(rh<=20 && rw<180 ){//如果要设定拖动区域可以作判断
	var ofsx = x - lx;
	thiso.style.left = (parseInt(thiso.style.left) + ofsx) +"px";
	lx = x;
	var ofsy = y - ly;
	thiso.style.top = (parseInt(thiso.style.top) + ofsy) +"px";
	ly = y;
 }else{
		canDrg=false;
  }
	//window.status=thiso.style.left+"left:top"+thiso.style.top+" rh:rw"+rh+"+"+rw +" x:"+x+"  y:"+y  +" lx:"+lx+"  ly:"+ly;
 }
}

document.onmouseup=function(){
	    canDrg=false;//拖拽变量设为false
 try{//设置渐变色;

  if(document.all)thiso.filters.Alpha.opacity=80;
  else thiso.style.MozOpacity=80/100;

}catch(e){
 // alert(e.toString());
}
	    if(document.all && thiso != null){
	    	//ie下,将清捕获;
         thiso.releaseCapture();
	     thiso = null;
   }
}


function set(obj){
     obj=obj.parentNode.parentNode;
     if(obj.getAttribute("rel"));
	   //obj.style.zIndex=1;
	   
}
function st(o){
/*
var p = o.parentNode;
if(p.lastChild != o){
  p.appendChild(o);
}*/


if(rh<=20 && rw>=180){
canDrg=false;
//如果选择的是关闭区域;
		  //window.status=rw+"|"+rh;
   closeconfirm();
		  /*
		  if(p.firstChild == o) return;
		  p.insertBefore(o, p.firstChild);
		  */
        }
}

//设定层的显示位置;
function setposition(obj){

   	   // alert(window.document.body.scrollHeight);
   	   // alert(window.document.body.scrollTop);
   	    $("mask").style.height = window.document.body.scrollHeight;
   	    var w = parseInt(obj.style.width);
   	    var h = parseInt(obj.style.height);   	  
   	    obj.style.left=(window.document.body.offsetWidth-w)/2+"px";
				//obj.style.left=(window.screen.width-w)/2+"px";
   	    //alert(window.screen.height+"-"+h);
   	   // alert((window.document.body.offsetHeight-h)+"/"+2+"+"+window.document.body.scrollTop)
   	    //if(!document.all)h=h*4;
   	    obj.style.top=(window.document.body.offsetHeight-h)/2+window.document.body.scrollTop+"px";
}




//获取随机颜色值;
function GetColor()
{
	var r = Math.floor(Math.random() * 255).toString(16);
	var g = Math.floor(Math.random() * 255).toString(16);
	var b = Math.floor(Math.random() * 255).toString(16);
	r = r.length == 1 ? "0" + r : r;
	g = g.length == 1 ? "0" + g : g;
	b = b.length == 1 ? "0" + b : b;
	return "#" + r + g + b;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -