<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>拖拽+改变大小</title>
<meta name="description" content="">
<meta name="keywords" content="">
<style>
*{margin:0; padding: 0;}
#box{background-color:#ddd; width: 300px; height:200px; position: relative;}
#box1{border-bottom:10px solid #bbb; border-left:10px solid transparent; width:0; height: 0; position:absolute; bottom:0; right: 0; cursor:nw-resize;}
</style>
<script>
window.onload = function(){
var oDiv = document.getElementById('box');
var oArrow = document.getElementById('box1');
oArrow.onmousedown = function(e){
var e = e||event;
var disX = e.clientX - oDiv.offsetLeft;
var disY = e.clientY - oDiv.offsetTop;
if(oDiv.setCapture){
oDiv.onmousemove = fnMove;
oDiv.onmouseup = fnUp;
oDiv.setCapture();
}else{
oDiv.onmousemove = fnMove;
oDiv.onmouseup = fnUp;
}
function fnMove(e){
var e = e||event;
var l = e.clientX + oArrow.offsetWidth;
var t = e.clientY + oArrow.offsetHeight;
this.style.width = l+'px';
this.style.height = t+'px';
}
function fnUp(){
this.onmousemove = null;
this.onmouseup = null;
if(this.releaseCapture){
this.releaseCapture();
}
}
return false;
}
}
</script>
</head>
<body>
<div id="box">
<div id="box1"></div>
</div>
</body>
</html>
拖拽+改变大小
最新推荐文章于 2021-06-08 11:24:13 发布