javascriptjqueryhtmlcss

How to resize image in Webpage with mouse


I want to move and resize the image in the web with mouse.
So I tried to that with Jquery.
Draggable of Jquery works well, but resizable doesn't work.
What's the problem in my code?
And Could you recommend other methods except for jquery?

<script>   
$( function() {
    $( "#yoman" ).draggable();
});

$( function() {
    $( "#yoman" ).resizable();
});
</script>

</head> 

<body>
    <div id="yoman" class="ui-widget-content">
        <img src = "https://www.froala.com/assets/blog/pages/post41_2.png" width="100px" height="100px">
    </div>
</body>

Solution

  • This is a simple solution. There are many others. With this approach, you can resize the image by pulling the image's lower right corner.

    .resizable {
      display: inline-block;
      background: red;
      resize: both;
      overflow: hidden;
      line-height: 0;
      }
    
    .resizable img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
    <div class='resizable'>
    <img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/bb/Pigeon_Point_Lighthouse_%282016%29.jpg/220px-Pigeon_Point_Lighthouse_%282016%29.jpg" alt="">  
    </div>