js 火狐+IE兼容 拖动层。修改:可创建层。绑定事件

addNode("ssss","aaaa");
addNode("kaka","ss");
function addNode(divid,titleid){
div=document.createElement("DIV");
div.style.cssText="position: absolute; width: 216px; height: 138px; background-color: #dddddd;font-size: 12px; top: 210px; left: 180px; z-index: 101; border: solid 1px #000;"
div.id=divid;
div2=document.createElement("DIV");;
div2.style.cssText="background-color: #000000; cursor: move; height: 20px; color: #fff;font-size: 12px; padding-top: 5px; padding-left:10px;";
div2.id=titleid;
div.appendChild(div2);
document.getElementById("context").appendChild(div);
document.getElementById(titleid).onmouseover=function(e){
    band(divid,titleid);
}
}

function band(divid,titleid){
var posX;
var posY;       

fdiv = document.getElementById(divid);           
document.getElementById(titleid).onmousedown=function(e)
{
    if(!e) e = window.event;  //IE
    posX = e.clientX - parseInt(fdiv.style.left);
    posY = e.clientY - parseInt(fdiv.style.top);
    document.onmousemove = mousemove;           
}
document.onmouseup = function()
{
    document.onmousemove = null;
}
function mousemove(ev)
{
    if(ev==null) ev = window.event;//IE
    fdiv.style.left = (ev.clientX - posX) + "px";
    fdiv.style.top = (ev.clientY - posY) + "px";
}
}

你可能感兴趣的:(js 火狐+IE兼容 拖动层。修改:可创建层。绑定事件)