Ajax Blog 用到的几个函数
更新时间:2006年10月03日 00:00:00 作者:
drag.js主要用于移动
复制代码 代码如下:
var x0=0,y0=0,x1=0,y1=0;
var offx=6,offy=6;
var moveable=false;
var normal='#C6E7FF'; //正常时的背景颜色
var index=10000; //z-index;
//开始拖动;
function startDrag(obj)
{
if(event.button==1)
{
obj.setCapture(); //锁定标题栏;
var win = obj.parentNode; //定义对象;
x0 = event.clientX; //记录鼠标和层位置;
y0 = event.clientY;
x1 = parseInt(win.style.left);
y1 = parseInt(win.style.top);
moveable = true;
}
}
//拖动;
function drag(obj)
{
if(moveable)
{
var win = obj.parentNode;
win.style.left = x1 + event.clientX - x0;
win.style.top = y1 + event.clientY - y0;
}
}
//停止拖动;
function stopDrag(obj)
{
if(moveable)
{
obj.releaseCapture();
moveable = false;
}
}
//获得焦点;
function getFocus(obj)
{
if(obj.style.zIndex!=index)
{
index = index + 2;
var idx = index;
obj.style.zIndex=idx;
obj.nextSibling.style.zIndex=idx-1;
}
}
//最小化;
function min(obj)
{
var win=obj.parentNode.parentNode.parentNode;
var msg=win.childNodes;
var flg=msg(1).style.display;
if(flg=="none")
{
msg(1).style.display = "block";
obj.src= "images/opentriangle.gif";
}else{
msg(1).style.display = "none";
obj.src= "images/TRIANGLE.GIF";
}
}
//创建一个对象;
function xWin(id,w,h,l,t,tit,msg)
{
index = index+2;
this.id = id;
this.width = w;
this.height = h;
this.left = l;
this.top = t;
this.zIndex = index;
this.title = tit;
this.message = msg;
this.obj = null;
this.bulid = bulid;
this.bulid();
}
//初始化;
function bulid()
{
var str = ""
+ "<div id=xMsg" + this.id + " "
+ "style='"
+ "z-index:" + this.zIndex + ";"
+ "width:" + this.width + ";"
+ "left:" + this.left + ";"
+ "top:" + this.top + ";"
+ "background-color:#fff;"
+ "color:#000;"
+ "font-size:14px;"
+ "position:absolute;"
+ "display:none;"
+ "border:#6BC3FF 1px solid ;'"
+ "onmousedown='getFocus(this)'>"
+ "<div "
+ "style='"
+ "background-color:" + normal + ";"
+ "width:" + (this.width+5) + ";"
+ "line-height:26px;cursor:move;border:1px #ccc solid;"
+ "margin:1px;vertical-align:middle"
+ "' "
+ "onmousedown='startDrag(this)' "
+ "onmouseup='stopDrag(this)' "
+ "onmousemove='drag(this)' "
+ "ondblclick='min(this.childNodes[1])'"
+ ">"
+ "<span style='float:left;width:50%;text-align:left;padding-left:3px;font-weight:bold;'>" + this.title +""+"</span>"
+ "<span style='float:right;width:47%;text-align:right;padding-right:3px;padding-top:5px;'> "
+"<img src='images/opentriangle.GIF' onclick='min(this)' style='cursor:pointer;'/> "
+"<img src='images/CloseBtn.gif' onclick='$SHwin(\""+this.id+"\")' style='cursor:pointer;'/></span>"
+ "</div>"
+ "<div style='"
+ "width:100%;"
+ "height:" + this.height + ";"
+ "background-color:white;"
+ "line-height:14px;"
+ "word-break:break-all;"
+ "padding:3px;"
+ "'>" + this.message + "</div>"
+ "</div>"
document.body.insertAdjacentHTML("beforeEnd",str);
}
function $SHwin(id){
if(document.getElementById("xMsg"+id).style.display=='none'){
document.getElementById("xMsg"+id).style.display='block';
}
else{
document.getElementById("xMsg"+id).style.display='none';
}
}
相关文章
js中获取键盘按下键值event.keyCode、event.charCode和event.which的兼容性详解
这篇文章主要给大家介绍了关于Javascript中获取键盘按下键值event.keyCode、event.charCode和event.which的兼容性的相关资料,文中介绍的非常详细,需要的朋友可以参考借鉴,下面来一起看看吧。2017-03-03js中toString()函数与valueOf()函数使用与区别
在等于运算符中,如果比较的内容包含对象类型数据,则会涉及隐式转换,那么就会调用toString()函数和valueOf()函数,本文主要介绍了 js中toString()函数与valueOf()函数使用与区别,感兴趣的可以了解一下2022-04-04
最新评论