Let me share what I actually want -
- Create a div.
- Onclick add an image to the div.
- Make this image draggable and resizable.
- We would be able to add multiple image into the div.
Below is my code I've done so far -
JS :
$.fn.extend({
draggableChildren: function(selector) {
$(this).on("mouseover", selector, function() {
if(!$(this).is(":ui-draggable"))
$(this).draggable({ containment: "parent" });
});
return this;
}
});
$.fn.extend({
resizableChildren: function(selector) {
$(this).on("mouseover", selector, function() {
if(!$(this).is(":ui-resizable"))
$(this).resizable({ containment: "parent" });
});
}
});
$(document).ready(function(){
setImageProperty=function(imageSource){
$(".block").draggableChildren(".blocks");
$(".block").resizableChildren(".blocks");
$(".block").append('<img class="blocks" src='+imageSource+' />');
}});
CSS :
.blocks
{
display: inline-block;
width: 30%;
}
.block
{
width:50%;
height : 50%;
padding:10px;
border:1px solid #C8C8C8;
margin:0px;
background-color:#F0F0F0;
margin-left: auto;
margin-right: auto;
position : relative;
overflow: hidden;
}
HTML:
<!DOCTYPE html>
<head>
<meta content="text/html; charset=utf-8" />
<title>Upload Image</title>
<script src="../js/jquery-1.11.0.min.js"></script>
<script src="../js/jquery-ui.js"></script>
<script src="../js/upload_common.js"></script>
<link rel="stylesheet" href="../css/jquery-ui.css" />
<link rel="stylesheet" href="../css/upload_common.css" />
</head>
<body>
<br><div class="block"></div>
<center>
<br>
<input class="button" type="button" id="showExistingImg" value="Show Uploaded Images" />
<input id="style_Browse" type="button" value="Upload Images" class="button" />
<input id="btn_browse" type="file" onchange="loadname(this,'previewImg');" />
<div id="existingImges">
<br>
<a class="block-add" href="javascript:void(0)" onclick="setImageProperty('../images/1.jpg')" ><img class="uploadImage" src="../images/1.jpg" /></a>
<a class="block-add" href="javascript:void(0)" onclick="setImageProperty('../images/2.jpg')" ><img class="uploadImage" src="../images/2.jpg" /></a>
<a class="block-add" href="javascript:void(0)" onclick="setImageProperty('../images/3.jpg')" ><img class="uploadImage" src="../images/3.jpg" /></a>
</center>
</body>
</html>
Problem is I can make the image either draggable or resizable. Not both. For instance, in the code above, the image is resizable, not draggable. Can anyone please guide me what I am doing wrong?
Please find the attached fiddle : http://jsfiddle.net/8VY52/249/
Update: I simplified your code a little bit. Here is the link: http://jsfiddle.net/lotusgodkk/8VY52/250/
I hope this is what you are looking for.
Javascript:
HTML:
You should wrap image into a div and then bind draggable on the container and resizable on the image. It has something to do with how jQuery draggable and resizable works.
jQuery Ticket for resizable and draggable on image
Example code: http://jsfiddle.net/lotusgodkk/8VY52/247/
HTML: