码迷,mamicode.com
首页 > 其他好文 > 详细

可拖动大小div案例

时间:2015-06-16 16:16:06      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:

<!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>  

 

可拖动大小div案例

标签:

原文地址:http://www.cnblogs.com/yudishow/p/4580771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!