📄 drag.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 d_width = 550;
var d_height = 30;
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);
rw = parseInt(x)-parseInt(getAbsoluteLeft(o));
//rh=parseInt(y)-parseInt(o.style.top);
rh = parseInt(y)-parseInt(getAbsoluteTop(o));
//rw = Math.abs(rw);
//rh = Math.abs(rh);
//document.title=rw+"=文本区域="+rh;
//if(rh<=d_height && rw>=d_width &&rh>0)document.title=rw+"||20*20||"+rh;//右上角20*20的关闭区域
//if(rh<=d_height && rw<d_width &&rh>0)document.title=rw+"||可选||"+rh;//绝对拖动条选择区域;
//o.releaseCapture();
}
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<=d_height && rw<d_width &&rh>0){//设定在拖动区域
if(document.all)thiso.filters.Alpha.opacity=80;
else thiso.style.MozOpacity=80/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<=d_height && rw<d_width &&rh>0){//如果要设定拖动区域可以作判断
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=100;
else thiso.style.MozOpacity=100;
}catch(e){
// alert(e.toString());
}
if(document.all && thiso != null){
//ie下,将清空捕获;
thiso.releaseCapture();
thiso = null;
}
}
function st(o){
if(rh <= d_height && rw >= d_width){
canDrg=false;
showHide($("sitelistDiv"));
}
}
function showHide(obj,self){
obj.style.display = obj.style.display=="none"?"":"none";
//$("del_icon").display="none";
var icon = "1";
var text = "OPEN";
if(obj.style.display==""){
icon = "2";
text = "CLOSE";
}
$("max_min").childNodes[0].innerHTML = icon;
$("max_min").childNodes[1].nodeValue = text;
}
//设定层的显示位置;
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;
}
//推出时调用cookie
window.onunload = function(){
setCookie("siteMainDargLeft",getAbsoluteLeft( $("siteMainDarg") ) );
setCookie("siteMainDargTop",getAbsoluteTop( $("siteMainDarg") ) );
setCookie("sitelistDivDisplay",$("sitelistDiv").style.display );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -