js玩具——UI组件:边距

/*
 * 边距
 *  author: 吴安国
 * version: 1.0
 */ 
function Margin() {	
	switch(arguments.length) {
	case 0:
		throw new Error("Margin参数错误");
		break;
	case 1:
		this.left = this.right = this.top = this.bottom = arguments[0];
		break;
	case 2:
		this.top = this.bottom = arguments[0];
		this.left = this.right = arguments[1];		
		break;
	case 3:
		this.top = arguments[0];
		this.left = this.right = arguments[1];
		this.bottom = arguments[2];		
		break; 
	case 4:
	default:
		this.top = arguments[0];
		this.right = arguments[1];
		this.bottom = arguments[2];
		this.left = arguments[3];
		break;	
	}
}

/**
 * 左边边距
 * @return left
 */
Margin.prototype.getLeft = function() {
	return "'" + this.left + "'";
};

/**
 * 右边边距
 * @return right
 */
Margin.prototype.getRight = function() {
	return "'" + this.right + "'";
};

/**
 * 上边边距
 * @return top
 */
Margin.prototype.getTop = function() {
	return "'" + this.top + "'";
};

/**
 * 下边边距
 * @return bottom
 */
Margin.prototype.getBottom = function() {
	return "'" + this.bottom + "'";
};

Margin.prototype.toString = function() {
	var sb = new StringBuffer("'");
	sb.append(this.top).append(" ");
	sb.append(this.right).append(" ");
	sb.append(this.bottom).append(" ");
	sb.append(this.left).append("'");
	return sb.toString();
};

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值