function getByClass(clsname,parent){
var oParent=parent?document.getElementById(parent):document;//找到光标按下的元素范围
eles=[];//创建数组
elements=oParent.getElementsByTagName("*");//获取所有符合条件的弹框节点
for(var i=0,l=elements.length;i<l;i++) {
if(elements[i].className==clsname) {
eles.push(elements[i]);//增加符合条件的节点 }
}
return eles;}window.onload=drag;//调用函数drag()
function drag(){
var oTitle=getByClass("login_logo_webqq","loginPanel")[0];//获取符合条件的节点范围
//拖曳
oTitle.onmousedown=fnDown();//调用函数fnDown()
//关闭
var oClose=document.getElementById("ui_boxyClose");
oClose.onclick=function(){
document.getElementById("loginPanel").style.display="none";
}
}
function fnDown(event){
event = event || window.event;
var oDrag=document.getElementById('loginPanel'),//获取弹框
//鼠标按下时光标与面板之间的距离
disX=event.clientX-oDrag.offsetLeft,
disY=event.clientY-oDrag.offsetTop;
//移动
document.onmousemove=function(event){
event = event || window.event;
fnMove(event,disX,disY); }
//释放鼠标
document.onmouseup=function() {
document.onmousemove=null;
document.onmouseup=null; }
}
function fnMove(e,posX,posY){
var oDrag=document.getElementById('loginPanel');//获取弹框
l=e.clientX-posX;
t=e.clientY-posY;
WinW=document.documentElement.clientWidth || document.body.clientWidth;
WinH=document.documentElement.clientHeight || document.body.clientHeight;
maxW=WinW-oDrag.offsetWidth;
maxH=WinH-oDrag.offsetHeight;
if(l<0){
l=0;
}else if(l>maxW){
l=maxW;
}
if(t<0){
t=0;
}else if(t>maxH){
t=maxH;
}
oDrag.style.left=l+'px';
oDrag.style.top=t+'px';
}
添加回答
举报
0/150
提交
取消