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; function drag() { var otitle=getByClass('login_logo_webqq','loginPanel')[0]; otitle.onmousedown=fnDown; } 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); } } function fnMove(e,posX,posY){ var oDrag=document.getElementById('loginPanel'), l=e.clientX-posX, t=e.clientY-posY, oDrag.style.left=l+'px' oDrag.style.top=t+'px' }