div 拖拽

/* 图标功能加载*/
pageCommon.nav = function () {
var posX;
var posY;
var fwuss = $(".quick-nav")[0];
fwuss.onmousedown = function(e) {
//鼠标聚焦
fwuss.setCapture && fwuss.setCapture();
var disX = (e || event).clientX;
var disY = (e || event).clientY;
posX = disX - fwuss.offsetLeft;//获得横坐标x
posY = disY - fwuss.offsetTop;//获得纵坐标y
//监听拖拽线高
document.onmousemove = function(ev) {
//鼠标距离
var iT = (ev || event).clientX - posX;
var eT = (ev || event).clientY - posY;
fwuss.style.margin = 0;
fwuss.style.left = iT + "px";
fwuss.style.right = "unset";
fwuss.style.top = eT + "px";
return false
}
document.onmouseup = function() {
document.onmousemove = null;
document.onmouseup = null;
fwuss.releaseCapture && fwuss.releaseCapture();
};
return false
};

}

你可能感兴趣的:(div 拖拽)