Skip to content

Instantly share code, notes, and snippets.

@shibayu36
Created December 6, 2012 03:12
Show Gist options
  • Save shibayu36/4221539 to your computer and use it in GitHub Desktop.
Save shibayu36/4221539 to your computer and use it in GitHub Desktop.
jquery resizable keeping aspect ratio
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery Resizable</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/themes/base/jquery-ui.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
<script src="./jquery-resizable.js"></script>
</head>
<body>
<div id="resizable" style="width: 200px; height: 200px; background-color: yellow;"></div>
</body>
</html>
$(function($) {
var $resizable = $('#resizable');
var width = $resizable.width();
var height = $resizable.height();
$resizable.resizable({
aspectRatio: width / height
});
$resizable.live("resizestop", function (event, ui) {
var size = ui.size;
console.log(size.width);
console.log(size.height);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment