我们刚刚花了不少时间在IE7/8中追踪一些非常奇怪的jQuery/css行为。
我们进行了一些动画和高度测量。在进行动画时,我们不希望文本换行。所以我们做了这个:
$(selector).css("white-space", "nowrap");
... animate ...
$(selector).css("white-space", "inherit");
在火狐,谷歌浏览器,Safari、iPad和IE9等浏览器中,这个功能表现非常好。但是在IE7或8中,我们遇到了一个JavaScript错误:
"Could not get the whiteSpace property. Invalid argument"
在jQuery的深处。经过一番思考,我们最终做了以下操作:
首先,在.css中定义一个类:
/* Kludge to avoid IE7/8-jQuery css('white-space') problem? */
.nowrap { white-space: nowrap; }
然后修改以上动画代码:
$(selector).addClass("nowrap");
... animate ...
$(selector).removeClass("nowrap");
现在大家都很高兴,但是这个拙劣的代码真的让我很烦恼。jQuery是否可以为IE执行一些CSS翻译?我们使用的是jQuery 1.4.2版本。