首页 > 代码库 > 拖拽边缘改变窗口(物体)大小
拖拽边缘改变窗口(物体)大小
<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>
拖拽边缘改变窗口(物体)大小
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。