<!DOCTYPE html> <html> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>drag div</title> <style type="text/css"> <style type="text/css"> 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;} #box div{position:absolute;width:100%;} #top,#bottom{color:#FFF;height:100%;overflow:hidden;} #bottom{<span style="color:#ff0000;BACKGROUND-COLOR: #3333ff">background-color:white;</span>top:50%} #line{top:50%;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"), 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 = oBottom.style.top = iT + "px"; return false }; document.onmouseup = function() { document.onmousemove = null; document.onmouseup = null; oLine.releaseCapture && oLine.releaseCapture() }; oLine.setCapture && oLine.setCapture(); return false }; }; </script> <div id="box"> <div id="top"> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> </div> <div id="bottom"> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> <font color='black'>2</font></br> </div> <div id="line"></div> </div> </body> </html>