James Thomas
James Thomas

Reputation: 169

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>

Upvotes: 6

Views: 8657

Answers (3)

Pablo Darde
Pablo Darde

Reputation: 6432

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>

Upvotes: 11

PIZZZZZZZZZZZA is here
PIZZZZZZZZZZZA is here

Reputation: 145

See jqueryui.com - resizable

to see your pic, add this css CSS the:

#yoman { width: 100%; height: 100%; padding: 1.4324352342342423em; margin: 1px;} 

Links: Diary.com - resize a image with HTML & JS

Stackoverflow - HTML5 Pre-resize images before uploading

Stackoverflow - Konva.Js crop and resize

Upvotes: 0

Leena Lavanya
Leena Lavanya

Reputation: 333

Try including this CSS file on your site:

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

jQuery .resizable() requires the styling from jQueryUI's CSS to work.

Upvotes: 1

Related Questions