JSFiddle - React, Tailwind, and code Playground
by digitaloutback
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js"></script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/redmond/jquery-ui.css" rel="stylesheet" />
<div id="canvas">
<div class='lyr'></div>
<div class='lyr lyr2'></div>
<div class='resizer'></div>
</div>
CSS
#canvas { width: 500px; height: 300px; position: relative; background: #eee}
.lyr {
background: yellow;
position: absolute;
left: 150px; top: 50px;
width: 100px; height: 100px;
}
.lyr2 {
background: blue;
left: 170px; top: 70px;
width: 130px; height: 100px;
z-index: 100;
}
.resizer { border: 1px dashed #333; left: 150px; top: 50px; width: 150px; height: 120px; position: absolute;
}
JavaScript
// Resizable
$('.resizer').resizable({
aspectRatio: true,
handles: 'all',
alsoResize: '.lyr'
});
/*
* Resizable Extensions
*/
$.ui.plugin.add("resizable", "alsoResize", {
start: function(event, ui) {
var self = $(this).data("resizable"),
o = self.options;
var _store = function(exp) {
$(exp).each(function() {
var el = $(this);
el.data("resizable-alsoresize", {
width: parseInt(el.width(), 10),
height: parseInt(el.height(), 10),
left: parseInt(el.css('left'), 10),
top: parseInt(el.css('top'), 10),
position: el.css('position') // to reset Opera on stop()
});
});
};
if (typeof(o.alsoResize) == 'object' && !o.alsoResize.parentNode) {
if (o.alsoResize.length) {
o.alsoResize = o.alsoResize[0];
_store(o.alsoResize);
}
else {
$.each(o.alsoResize, function(exp) {
_store(exp);
});
}
} else {
_store(o.alsoResize);
}
},
resize: function(event, ui) {
var self = $(this).data("resizable"),
o = self.options,
os = self.originalSize,
op = self.originalPosition;
var delta = {
height: (self.size.height - os.height) || 0,
width: (self.size.width - os.width) || 0,
top: (self.position.top - op.top) || 0,
left: (self.position.left - op.left) || 0
},
_alsoResize = function(exp, c) {
$(exp).each(function() {
var el = $(this),
start = $(this).data("resizable-alsoresize"),
style = {},
css = c && c.length ? c : el.parents(ui.originalElement[0]).length ? ['width',...