釋出一個鎖定行列的一種方法。(實現Excel裡的凍結窗格的功能)
阿新 • • 發佈:2019-01-06
{
var dMain = document.getElementById("dMain"); //主Div
var dTop = document.getElementById("dTop"); //鎖定行的Div
var dLeft = document.getElementById("dLeft"); //鎖定列的Div
var dMid = document.getElementById("dMid"); //左上角的Div
var windowWidth = document.body.scrollWidth;
var windowHeight = document.body.clientHeight;
//alert(windowWidth);
dMain.style.background="#ffffff";
//alert(windowHeight);
dMain.style.width = windowWidth -12;
//修正
var sch = document.getElementById("div_Search");
//alert(sch.scrollHeight);
if (sch.style.display =="")
{
dMain.style.height = windowHeight -100- sch.scrollHeight;
}
else
{
dMain.style.height = windowHeight -120;
}
//dMain.style.display = "none";
//尋找Top 和 Left
var tt = dMain; // 尋找左上角的座標,程式碼來自梅花雪的日期控制元件
var th = tt;
var ttop = tt.offsetTop;
var thei = tt.clientHeight;
var tleft = tt.offsetLeft;
var ttyp = tt.type;
while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
var myTop = (ttyp=="image")? ttop+thei : ttop+thei+6; //左上角的座標
var myLeft = tleft; //左上角的座標
//===================================尋找完畢===============
hh = dMain.style.height; //修正
hh = hh.replace("px","");
myTop = myTop - hh +12;
var dg = document.getElementById("DG"); //顯示資料的表格
var RowsCount ="1"; //鎖定行數
var LineCount ="1"; //鎖定列數
//鎖定行的高度
var RowsHeight = dg.rows[RowsCount].cells[0].offsetTop - dg.rows[0].cells[0].offsetTop +2
//鎖定列的寬度
var LineWidth = dg.rows[0].cells[LineCount].offsetLeft - dg.rows[0].cells[0].offsetLeft +2
//鎖定列的高度
var LineHeight = dMain.style.height;
LineHeight = LineHeight.replace("px","");
//鎖定行的寬度
var RowsWidth = dMain.style.width;
RowsWidth = RowsWidth.replace("px","");
//hh = parseint(hh);
//賦值
divResize(dMain,dTop,dLeft,dMid);
if (RowsHeight <25)
RowsHeight =25;
if (LineWidth <20)
LineWidth =20;
dTop.style.width = RowsWidth -16;
dTop.style.height = RowsHeight;
dLeft.style.width = LineWidth;
dLeft.style.height = LineHeight -16;
dMid.style.width = LineWidth ;
dMid.style.height = RowsHeight;
//設定左上角的位置
dTop.style.top = myTop ;
dTop.style.left = myLeft ;
dLeft.style.top = myTop;
dLeft.style.left = myLeft;
dMid.style.top = myTop;
dMid.style.left = myLeft;
}
var dMain = document.getElementById("dMain"); //主Div
var dTop = document.getElementById("dTop"); //鎖定行的Div
var dLeft = document.getElementById("dLeft"); //鎖定列的Div
var dMid = document.getElementById("dMid"); //左上角的Div
var windowWidth = document.body.scrollWidth;
//alert(windowWidth);
dMain.style.background="#ffffff";
//alert(windowHeight);
dMain.style.width = windowWidth -12;
//修正
var sch = document.getElementById("div_Search");
//alert(sch.scrollHeight);
if (sch.style.display =="")
{
dMain.style.height
}
else
{
dMain.style.height = windowHeight -120;
}
//dMain.style.display = "none";
//尋找Top 和 Left
var tt = dMain; // 尋找左上角的座標,程式碼來自梅花雪的日期控制元件
var th = tt;
var ttop = tt.offsetTop;
var thei = tt.clientHeight;
var ttyp = tt.type;
while (tt = tt.offsetParent){ttop+=tt.offsetTop; tleft+=tt.offsetLeft;}
var myTop = (ttyp=="image")? ttop+thei : ttop+thei+6; //左上角的座標
var myLeft = tleft; //左上角的座標
//===================================尋找完畢===============
hh = dMain.style.height; //修正
hh = hh.replace("px","");
myTop = myTop - hh +12;
var dg = document.getElementById("DG"); //顯示資料的表格
var RowsCount ="1"; //鎖定行數
var LineCount ="1"; //鎖定列數
//鎖定行的高度
var RowsHeight = dg.rows[RowsCount].cells[0].offsetTop - dg.rows[0].cells[0].offsetTop +2
//鎖定列的寬度
var LineWidth = dg.rows[0].cells[LineCount].offsetLeft - dg.rows[0].cells[0].offsetLeft +2
//鎖定列的高度
var LineHeight = dMain.style.height;
LineHeight = LineHeight.replace("px","");
//鎖定行的寬度
var RowsWidth = dMain.style.width;
RowsWidth = RowsWidth.replace("px","");
//hh = parseint(hh);
//賦值
divResize(dMain,dTop,dLeft,dMid);
if (RowsHeight <25)
RowsHeight =25;
if (LineWidth <20)
LineWidth =20;
dTop.style.width = RowsWidth -16;
dTop.style.height = RowsHeight;
dLeft.style.width = LineWidth;
dLeft.style.height = LineHeight -16;
dMid.style.width = LineWidth ;
dMid.style.height = RowsHeight;
//設定左上角的位置
dTop.style.top = myTop ;
dTop.style.left = myLeft ;
dLeft.style.top = myTop;
dLeft.style.left = myLeft;
dMid.style.top = myTop;
dMid.style.left = myLeft;
}