我想實現使用jQuery像下面列大小調整(請參閱http://jsbin.com/uduNUbo/1/edit)實現使用jQuery
這裏是我的JS代碼
function resizeEvents(selector) {
function XY(e, ele) {
var parentOffset = ele.parent().offset();
return e.pageX - parentOffset.left;
}
var checkPos;
$(selector).on('mousedown', function() {
$(this).attr('init', true);
return false;
});
$(selector).on('mouseup', function() {
$(this).attr('init', false);
});
$(selector).closest('div').on('mousemove', function (e) {
var inits = $(this).find('.resize').filter(function(){
return $(this).attr('init') == true;
});
if (inits.length > 0) {
var pos = XY(e, inits.first());
if (!checkPos) {
checkPos = pos;
return false;
} else {
var moved = checkPos - pos, a = moved > 0 ? 1 : -1 ;
th.prevAll().each(function() {
if (!$(this).hasClass('.resize')) {
$(this).width($(this).width() + a);
}
});
th.nextAll().each(function() {
if (!$(this).hasClass('.resize')) {
$(this).width($(this).width() - a);
}
});
}
}
});
}
resizeEvents('.resize');
但是,這是行不通的,我的問題是Is mousemove is written properly, to define properly on correct element or not
。
如果它不那麼它的工作沒有正確寫的,不是嗎? – jcubic