body {
background: yellowgreen;
}
* {
margin: 0;
padding: 0;
}
#box1 {
position: relative;
width: 200px;
height: 200px;
background: #000;
}
#box2 {
position: absolute;
width: 50px;
height: 50px;
background: yellow;
right: 0;
bottom: 0;
}
<div id="box1">
<div id="box2"></div>
</div>
var box1 = document.getElementById("box1");
var box2 = document.getElementById("box2");
box2.onmousedown = function(e) {
var e = e || window.event;
var x = e.clientX;
var y = e.clientY;
var width = box1.offsetWidth;
var height = box1.offsetHeight;
document.onmousemove = function(e) {
var e = e || window.event;
box1.style.width = width + e.clientX - x + "px";
box1.style.height = height + e.clientY - y + "px";
}
}
box2.onmouseup = function() {
document.onmousemove = null;
}