Ajax Blog 用到的幾個函數(shù)第3/3頁
更新時間: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";
}
}
//創(chuàng)建一個對象;
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';
}
}
相關(guān)文章
js中獲取鍵盤按下鍵值event.keyCode、event.charCode和event.which的兼容性詳解
這篇文章主要給大家介紹了關(guān)于Javascript中獲取鍵盤按下鍵值event.keyCode、event.charCode和event.which的兼容性的相關(guān)資料,文中介紹的非常詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-03-03JavaScript中實現(xiàn)最高效的數(shù)組亂序方法
這篇文章主要介紹了JavaScript中實現(xiàn)最高效的數(shù)組亂序方法,數(shù)組亂序的意思是,把數(shù)組內(nèi)的所有元素排列順序打亂,需要的朋友可以參考下2014-10-10經(jīng)典的解除許多網(wǎng)站無法復制文字的絕招
經(jīng)典的解除許多網(wǎng)站無法復制文字的絕招...2006-12-12?js中toString()函數(shù)與valueOf()函數(shù)使用與區(qū)別
在等于運算符中,如果比較的內(nèi)容包含對象類型數(shù)據(jù),則會涉及隱式轉(zhuǎn)換,那么就會調(diào)用toString()函數(shù)和valueOf()函數(shù),本文主要介紹了?js中toString()函數(shù)與valueOf()函數(shù)使用與區(qū)別,感興趣的可以了解一下2022-04-04javascript實現(xiàn)帶節(jié)日和農(nóng)歷的日歷特效
這篇文章主要介紹了javascript實現(xiàn)帶節(jié)日和農(nóng)歷的日歷特效,效果十分棒,需要的朋友可以參考下2015-02-02