jqueryUI小插件--随意改变div大小

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<style type="text/css">
*{padding: 0;margin:0;}
#div1{
width:100px;
height: 100px;
background: green;
}
#div2{
position: absolute;
width:20px;
height: 20px;
background: red;
margin-top: 80px;
margin-left: 80px;
}
</style>
</head>
<body>
<div id="div1">
<div id="div2"></div>
 </div> 
 <input type="textarea">
</body>
<script type="text/javascript">
$(document).ready(function(){
  var resizediv=function(){
  $("#div2").mousedown(function(x){ 
      $(document).mousemove(function(e,x){ 
      $("#div1").css('width',e.pageX+10);
        $("#div1").css('height',e.pageY+10);
        $("#div2").css('margin-left',e.pageX-10);
        $("#div2").css('margin-top',e.pageY-10);
      });
    $(document).mouseup(function(e){ 
       $(document).unbind( 'mousemove' );
    });
  });
  };
  resizediv();
});
</script>
</html>

猜你喜欢

转载自blog.csdn.net/qq_39047764/article/details/79594623