document.onmousemove = fnMove(e,disX,disY);document.onmousemove=function(event){ event = event || window.event;
fnMove(event,disX,disY);
} 为什么方法一调用函数不成功?方法二可以成功下面是我的源码:// JavaScript Document
window.onload = init;
//初始化函数,调用拖拽,关闭,选择下拉框的操作
function init(){
drag();
//closeX();
//selectState();
}
function getClsName(clsName, parent){
var oTitle = parent?document.getElementById(parent):document,
eles = [],
elements = oTitle.getElementsByTagName('*');
//alert(elements);
for(var i=0; i<elements.length; i++){
if(elements[i].className == clsName){
eles.push(elements[i]);
}
}
return eles;
}
//拖拽函数,调用点击鼠标,移动鼠标,松开鼠标的方法
function drag(){
//var loginPanel = document.getElementById('loginPanel');
var login_logo_webqq = getClsName('login_logo_webqq','loginPanel')[0];
//alert(login_logo_webqq.className);
login_logo_webqq.onmousedown = fnDown;
}
function fnDown(e){
e = e || window.event;
//记录下鼠标点击的位置与登录界面边缘的距离
var loginPanel = document.getElementById('loginPanel'),
disX = e.clientX - loginPanel.offsetLeft,
disY = e.clientY - loginPanel.offsetTop;
document.onmousemove = fnMove(e,disX,disY);
// 移动
// document.onmousemove=function(event){
// event = event || window.event;
// fnMove(event,disX,disY);
// }
//alert(disX+','+disY);
}
function fnMove(e,posX,posY){
e = e || window.event;
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-10,
maxH=winH-oDrag.offsetHeight;
if(l<0){
l=0;
}else if(l>maxW){
l=maxW;
}
if(t<0){
t=10;
}else if(t>maxH){
t=maxH;
}
oDrag.style.left=l+'px';
oDrag.style.top=t+'px';
}
添加回答
举报
0/150
提交
取消