Draggable and resizable in JqueryUI for an image is not working?

Ravichandran Jothi picture Ravichandran Jothi · May 22, 2012 · Viewed 16.8k times · Source

I used below code for dragging and resizing the image,

<!DOCTYPE html>
<html>
    <head lang="en">
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/themes/base/jquery-ui.css"/>

        <script type="text/javascript">
    $(document).ready(function() {

        $( "#img_content" ).draggable().resizable();

    });
    </script>
    </head>
    <body class='default'>       


<div class="demo">
<!--<div id="img_content" class="ui-widget-content">
    <p>Drag me around</p>
</div>-->

<img id="img_content" class="ui-widget-content" src="Tulips.jpg" />

</div>


    </body>
</html>

resizable is working corretly. but dragging the image not working. if i applied for div structure

<div id="img_content" class="ui-widget-content">
        <p>Drag me around</p>
    </div>

its working fine.

How do i implement drag and resize for image tag?

Answer

daniatic picture daniatic · Jan 21, 2013

You should wrap the image into a div with style="display:inline-block; and then make the div draggable and the image resizable. Working Example