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

拖拽边缘改变窗口(物体)大小

时间:2017-04-08 00:47:39      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:offset   onload   back   element   top   sed   null   round   rip   

技术分享

 

<body> 
  <div id="div1"></div>
</body>


<style>   #div1 {width: 100px; height: 100px; background: red; position: absolute; left: 500px; top: 200px;} </style>
<script>   window.onload = function() { var oDiv = document.getElementById(‘div1‘); oDiv.onmousedown = function(ev) { var ev = ev || event; var disW = this.offsetWidth; var disX = ev.clientX; var disL = this.offsetLeft; var b = ‘‘; if ( disX > disL + disW - 10 ) { //alert( ‘right‘ ); b = ‘right‘; } if ( disX < disL + 10 ) { //alert( ‘left‘ ); b = ‘left‘; } document.onmousemove = function(ev) { var ev = ev || event; switch( b ) { case ‘left‘: oDiv.style.width = disW - ( ev.clientX - disX ) + ‘px‘; oDiv.style.left = disL + ( ev.clientX - disX ) + ‘px‘; break; case ‘right‘: oDiv.style.width = disW + ( ev.clientX - disX ) + ‘px‘; break; } } document.onmouseup = function() { document.onmousemove = document.onmouseup = null; } return false; }   } </script>

拖拽边缘改变窗口(物体)大小

标签:offset   onload   back   element   top   sed   null   round   rip   

原文地址:http://www.cnblogs.com/chiangyibo/p/6680460.html

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