Created
September 21, 2010 19:32
-
-
Save higeorange/590362 to your computer and use it in GitHub Desktop.
要素縦方向のみリサイズ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
それっぽくは動く