当前位置: 代码迷 >> Web前端 >> 兼容chrome与firefox使用offsetWidth得到不同值的有关问题
  详细解决方案

兼容chrome与firefox使用offsetWidth得到不同值的有关问题

热度:113   发布时间:2012-11-22 00:16:41.0
兼容chrome与firefox使用offsetWidth得到不同值的问题

Ext3.x

?

Ext.MessageBox.alert 在chrome与firefox显示的宽度不一致问题

?

究其原因是因为msgEl.getWidth()得到的值不一致导致的

?

修正宽度应方法:

?

chrome:

?

rect = dom.getBoundingClientRect();

Math.ceil(rect.right - rect.left)

?

firefox:

?

dom.offsetWidth;

?

?

updateText : function(text) {
			if (!dlg.isVisible() && !opt.width) {
				dlg.setSize(this.maxWidth, 100);
			}

			msgEl.update(text ? text + ' ' : ' ');

			var iw = iconCls != '' ? (iconEl.getWidth() + iconEl
					.getMargins('lr')) : 0, mw = msgEl.getWidth()
					+ msgEl.getMargins('lr'), fw = dlg.getFrameWidth('lr'), bw = dlg.body
					.getFrameWidth('lr'), w;
			// @fixed chrome width
			if (Ext.isChrome) {
				rect = msgEl.dom.getBoundingClientRect();
				mw = Math.ceil(rect.right - rect.left);
			}

			w = Math.max(Math.min(opt.width || iw + mw + fw + bw, opt.maxWidth
					|| this.maxWidth), Math.max(opt.minWidth || this.minWidth,
					bwidth || 0));
?

?

  相关解决方案