js实现控件的拖拽功能

 
var width = 0;
var mX;
function msDown(obj) {
    obj.mouseDownX = 1;
    obj.setCapture();
    mX = event.clientX;
    var obj = document.getElementById("mainTable");
    width = obj.cells[0].style.width;
    width2 = obj.cells[2].style.width;
}
function msMove(obj) {
	var editBtn = document.getElementById("id.edit");
	if(editBtn!=null&&editBtn!=undefined&&editBtn.disabled==true){
		//editBtn.disabled==true Treemenu
		return false;
	}
    if (!obj.mouseDownX)
        return false;
    var moveX = event.clientX;
    var obj = document.getElementById("mainTable");
    var colWidth1 = parseInt(width) - (mX * 1 - moveX * 1) * 1;
    var colWidth2 = parseInt(width2) + (mX * 1 - moveX * 1) * 1;
    if (colWidth1 >= 0 && colWidth2 >= 0) {
        obj.cells[0].style.width = colWidth1;
        obj.cells[2].style.width = colWidth2;
    }
}
function msUp(obj) {
    obj.releaseCapture();
    obj.mouseDownX = 0;
}
function setTabCW() {
    setTimeout("setTabOnload()",10);
}
function setTabOnload(){
    var obj = document.getElementById("mainTable");
    var tabWidth = obj.clientWidth;
    obj.cells[0].style.width = (parseInt(tabWidth) -2) * 0.23;
    obj.cells[2].style.width = (parseInt(tabWidth) -2) * 0.77;
}

你可能感兴趣的:(js实现控件的拖拽功能)