Skip to content

Instantly share code, notes, and snippets.

@higeorange
Created September 21, 2010 19:32
Show Gist options
  • Save higeorange/590362 to your computer and use it in GitHub Desktop.
Save higeorange/590362 to your computer and use it in GitHub Desktop.
要素縦方向のみリサイズ
(function($) {
$.fn.resizable = function(options) {
var default_options = {
handleClass: "handle"
};
options = $.extend(default_options, options || {});
return this.each(function() {
addHandle(this, options);
});
}
function addHandle(el, options) {
var mousedown = false;
var mousedowny = 0;
var div = $("<div></div>");
var r = $(el);
var rh = r.height();
div.css("width", r.width());
div.addClass(options.handleClass);
r.after(div);
div.mousedown(function(e) {
mousedowny = e.pageY;
mousedown = true;
});
$(document).mousemove(function(e) {
if(mousedown) {
var diff = e.pageY - mousedowny;
r.css("height", diff + rh);
}
});
$(document).mouseup(function(e) {
mousedown = false;
mousedowny = 0;
rh = r.height();
});
}
})(jQuery);
@higeorange
Copy link
Author

それっぽくは動く

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment