jQuery Resizable and resize event
Show the use of resize event (from http://benalman.com/projects/jquery-resize-plugin/) using a resizable parent
by Avinash_R
HTML
<script src="https://raw.github.com/cowboy/jquery-resize/v1.1/jquery.ba-resize.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<div id="switcher"></div>
<div id="parent" class='ui-widget ui-corner-all'>
<div class="ui-overlay">
<div class='ui-widget-overlay'></div>
<div class="ui-widget-shadow ui-corner-all"></div>
</div>
<div id="child" class="ui-widget ui-widget-content ui-corner-all">
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
</div>
</div>
<script type="text/javascript"
src="http://jqueryui.com/themeroller/themeswitchertool/">
</script>
CSS
#parent{
height:200px;
}
#child{
width: 400px;
padding: .3em;
}
JavaScript
var parent = $('#parent');
var child = $('#child');
var shadow = $('.ui-widget-shadow');
$('#switcher').themeswitcher({
loadTheme: 'Black Tie'
});
$.resize.delay = 500;
parent.resize(function() {
child.css({
position: 'absolute',
top: parent.innerHeight() / 2 - child.outerHeight() / 2,
left: parent.innerWidth() / 2 - child.outerWidth() / 2
});
shadow.css({
position: 'absolute',
top: child.position().top,
left: child.position().left,
height: child.height() + 12,
width: child.width() + 12
});
}).resize();
parent.resizable({
minWidth: shadow.outerWidth() + 10,
minHeight: shadow.outerHeight() + 10,
handles: 'all'
}).draggable({parent: parent.parent()});