<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>例子</title> <style> ul,li{margin:0;padding:0;} body{font:14px/1.5 Arial;color:#666;} #box{position:relative;width:600px;height:400px;border:2px solid #000;margin:10px auto;overflow:hidden;} #box ul{list-style-position:inside;margin:10px;} #top,#bottom{color:#FFF;height:200px;overflow:hidden;} #top{background:green;} #bottom{background:blue;} #line{position:absolute;top:50%;width:100%;height:4px;overflow:hidden;margin-top:-2px;background:red;cursor:n-resize;} </style> <script> function $(id) { return document.getElementById(id) } window.onload = function() { var oBox = $("box"), oTop = $("top"), oBottom = $("bottom"), oLine = $("line"); oLine.onmousedown = function(e) { var disY = (e || event).clientY; oLine.top = oLine.offsetTop; document.onmousemove = function(e) { var iT = oLine.top + ((e || event).clientY - disY); var maxT = oBox.clientHeight - oLine.offsetHeight; oLine.style.margin = 0; iT < 0 && (iT = 0); iT > maxT && (iT = maxT); oLine.style.top = oTop.style.height = iT + "px"; oBottom.style.height = oBox.clientHeight - iT + "px"; return false }; document.onmouseup = function() { document.onmousemove = null; document.onmouseup = null; oLine.releaseCapture && oLine.releaseCapture() }; oLine.setCapture && oLine.setCapture(); return false }; }; </script></head><body><b>上下拖动红条改变显示区域高度</b><div id="box"> <div id="top"> <ul> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> <li>西安一大厦发生爆炸7人遇难31人受伤</li> </ul> </div> <div id="bottom"> <ul> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> <li>京沪高铁因质量问题被召回动车拟16日恢复运营</li> </ul> </div> <div id="line"></div></div></body></html>
时间: 2024-11-08 19:16:08