js改变行高 谁有现成的例子有上下两个div,如何用鼠标左键上下移动中间分割线改变这两个div的高度,但是保证这两个div的总高度固定,用div或table都可以谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 参考如下代码:<html><head><style type="text/css"> #div_line{height:5px;background:Gray;cursor:s-resize;} #div_top{height:200px;background:Red;} #div_bottom{height:200px;background:Blue;}</style></head><body><div id="div_top"></div><div id="div_line"></div><div id="div_bottom"></div><script>function addEventHandler(target, type, func) { if (target.addEventListener) target.addEventListener(type, func, false); else if (target.attachEvent) target.attachEvent("on" + type, func); else target["on" + type] = func;}function removeEventHandler(target, type, func) { if (target.removeEventListener) target.removeEventListener(type, func, false); else if (target.detachEvent) target.detachEvent("on" + type, func); else delete target["on" + type];}// 拖动高度相关(function() { var div_line = document.getElementById("div_line"); var div_top = document.getElementById("div_top"); var div_bottom = document.getElementById("div_bottom"); var minHeight = 20; var styleTop = div_top.currentStyle || document.defaultView.getComputedStyle(div_top, null); var styleBottom = div_bottom.currentStyle || document.defaultView.getComputedStyle(div_bottom, null); var styleLine = div_line.currentStyle || document.defaultView.getComputedStyle(div_line, null); var allHeight = parseInt(styleTop.height) + parseInt(styleLine.height) + parseInt(styleBottom.height); var downTop, downHeight; var targetMousedown = function (e) { downTop = e.clientY; downHeight = parseInt(styleTop.height); addEventHandler(document, "mousemove", documentMousemove); addEventHandler(document, "mouseup", documentMouseup); addEventHandler(div_line, "losecapture", documentMouseup); if (div_line.setCapture) div_line.setCapture(); addEventHandler(window, "blur", documentMouseup); if (e.preventDefault) e.preventDefault(); }; addEventHandler(div_line, "mousedown", targetMousedown); var documentMousemove = function (e) { if (window.getSelection) getSelection().removeAllRanges(); else if (document.selection && document.selection.empty) document.selection.empty(); var newHeight = downHeight + e.clientY - downTop; if (newHeight < minHeight || allHeight - newHeight < minHeight) return; div_top.style.height = newHeight + "px"; div_bottom.style.height = allHeight - newHeight + "px"; }; var documentMouseup = function (e) { removeEventHandler(document, "mousemove", documentMousemove); removeEventHandler(document, "mouseup", documentMouseup); removeEventHandler(div_line, "losecapture", documentMouseup); if (div_line.releaseCapture) div_line.releaseCapture(); removeEventHandler(window, "blur", documentMouseup); };})();</script></body></html> 不过我咋看你的风格很神似《pro javascript tech》呢 本帖最后由 zswang 于 2010-05-20 09:43:29 编辑 1楼的朋友能否帮我实现这个想法?第二个表格行高列宽改变时第一个表会自动改变~~~(第二表行高列宽可能是因为内容变化而改变的)<body> <div class="leftPanel" style="width:80%; border:1px solid #CCCFFF;"> <div class="leftTitle" style="width:40%; border:1px solid #ff0000;"> <table width="100%"> <tr rowspan="2" height="60px"> <th width="15%"><span class="LockCell LockCross lockRowBg">编号</span></th> <th width="25%"><span class="LockCell LockCross lockRowBg">部门</span></th> <th width="30%"><span class="LockCell LockCross lockRowBg">姓名</span></th> <th width="30%"><span class="LockCell LockCross lockRowBg">月份</span></th> </tr> </table> </div> <div class="leftContent" id="leftContent" style="width:40%; border:1px solid #CCCCFF;"> <table width="100%"> <tr height="30px"> <td width="15%">A1</td> <td width="25%">A2</td> <td width="30%">A3</td> <td width="30%">A4</td> </tr> <tr height="30px"> <td>B1</td> <td>B2</td> <td>B3</td> <td>B4</td> </tr> </table> </div> </div></body> -_-! 鼠标悬停 图片不停止? 关于在网页中插入javascript一个弱弱问题 高手进来帮我看看代码错在哪里? 求日志交叉得图形显示算法。 求一自动折叠、打开的浮动工具条 用javascript可以修改客户机注册表吗?请那位大狭指教一二 用javascript怎么访问<object>并改变它的属性呢? 平时只显示文本框1,当点击按钮后显示文本框2?? javascript中调用jsp FullCalendar日历插件 遇到个小问题 没有头绪 document.getElementById报“尚未实现”错误 javascript 选项卡 怎么加 cookie
<html>
<head>
<style type="text/css">
#div_line{height:5px;background:Gray;cursor:s-resize;}
#div_top{height:200px;background:Red;}
#div_bottom{height:200px;background:Blue;}
</style>
</head>
<body>
<div id="div_top"></div>
<div id="div_line"></div>
<div id="div_bottom"></div>
<script>
function addEventHandler(target, type, func) {
if (target.addEventListener)
target.addEventListener(type, func, false);
else if (target.attachEvent)
target.attachEvent("on" + type, func);
else target["on" + type] = func;
}function removeEventHandler(target, type, func) {
if (target.removeEventListener)
target.removeEventListener(type, func, false);
else if (target.detachEvent)
target.detachEvent("on" + type, func);
else delete target["on" + type];
}// 拖动高度相关
(function() {
var div_line = document.getElementById("div_line");
var div_top = document.getElementById("div_top");
var div_bottom = document.getElementById("div_bottom"); var minHeight = 20;
var styleTop = div_top.currentStyle || document.defaultView.getComputedStyle(div_top, null);
var styleBottom = div_bottom.currentStyle || document.defaultView.getComputedStyle(div_bottom, null);
var styleLine = div_line.currentStyle || document.defaultView.getComputedStyle(div_line, null);
var allHeight = parseInt(styleTop.height) + parseInt(styleLine.height) + parseInt(styleBottom.height);
var downTop, downHeight;
var targetMousedown = function (e) {
downTop = e.clientY;
downHeight = parseInt(styleTop.height);
addEventHandler(document, "mousemove", documentMousemove);
addEventHandler(document, "mouseup", documentMouseup);
addEventHandler(div_line, "losecapture", documentMouseup);
if (div_line.setCapture) div_line.setCapture();
addEventHandler(window, "blur", documentMouseup);
if (e.preventDefault) e.preventDefault();
};
addEventHandler(div_line, "mousedown", targetMousedown); var documentMousemove = function (e) {
if (window.getSelection)
getSelection().removeAllRanges();
else if (document.selection && document.selection.empty)
document.selection.empty();
var newHeight = downHeight + e.clientY - downTop;
if (newHeight < minHeight || allHeight - newHeight < minHeight) return;
div_top.style.height = newHeight + "px";
div_bottom.style.height = allHeight - newHeight + "px";
}; var documentMouseup = function (e) {
removeEventHandler(document, "mousemove", documentMousemove);
removeEventHandler(document, "mouseup", documentMouseup);
removeEventHandler(div_line, "losecapture", documentMouseup);
if (div_line.releaseCapture) div_line.releaseCapture();
removeEventHandler(window, "blur", documentMouseup);
};
})();
</script>
</body>
</html>
第二个表格行高列宽改变时第一个表会自动改变~~~
(第二表行高列宽可能是因为内容变化而改变的)<body>
<div class="leftPanel" style="width:80%; border:1px solid #CCCFFF;">
<div class="leftTitle" style="width:40%; border:1px solid #ff0000;">
<table width="100%">
<tr rowspan="2" height="60px">
<th width="15%"><span class="LockCell LockCross lockRowBg">编号</span></th>
<th width="25%"><span class="LockCell LockCross lockRowBg">部门</span></th>
<th width="30%"><span class="LockCell LockCross lockRowBg">姓名</span></th>
<th width="30%"><span class="LockCell LockCross lockRowBg">月份</span></th>
</tr>
</table>
</div>
<div class="leftContent" id="leftContent" style="width:40%; border:1px solid #CCCCFF;">
<table width="100%">
<tr height="30px">
<td width="15%">A1</td>
<td width="25%">A2</td>
<td width="30%">A3</td>
<td width="30%">A4</td>
</tr>
<tr height="30px">
<td>B1</td>
<td>B2</td>
<td>B3</td>
<td>B4</td>
</tr>
</table>
</div>
</div>
</body>