我可以优化这个 IE6 双 padding & 吗?使用 jQuery 选择器/过滤器来修复边距?
这是我修改的一些代码,用于修复 IE6 的双填充和双填充。边距问题:
// Apply double padding & margin fix for IE6
if ($.browser.msie && parseInt($.browser.version) < 7) {
var elements = self.common.$body.find("*").get();
for (var i = 0,
len = elements.length,
$e = $(elements[i]),
cssFloat = $e.css("float"),
cssDisplay = $e.css("display");
i < len;
i++) {
if (cssDisplay !== "none" &&
(cssFloat === "left" || cssFloat === "right")) {
$e.css("display", "inline");
}
};
}
我认为执行某种 jQuery.filter() 类型操作可能会更快,我首先只选择那些没有显示的元素: none; 并且有一个 float: left;
或 float: right;
。然后我可以循环遍历这些并简单地应用 display: inline;
修复。
你认为这行得通吗?如果是这样,该选择器会是什么样子?如果没有或者有更快的方法,请告诉我!
提前致谢!
Here is some code that I adapted to fix IE6's double padding & margin issue:
// Apply double padding & margin fix for IE6
if ($.browser.msie && parseInt($.browser.version) < 7) {
var elements = self.common.$body.find("*").get();
for (var i = 0,
len = elements.length,
$e = $(elements[i]),
cssFloat = $e.css("float"),
cssDisplay = $e.css("display");
i < len;
i++) {
if (cssDisplay !== "none" &&
(cssFloat === "left" || cssFloat === "right")) {
$e.css("display", "inline");
}
};
}
I was thinking it might be faster to do some sort of jQuery.filter()
type operation where I would start off by only selecting those elements that didn't have a display: none;
and that had a float: left;
or float: right;
. Then I could loop through those and simply apply the display: inline;
fix.
Do you think that would work? If so, what would that selector look like? If not or there is a quicker way, please do let me know!
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我决定在 jsPerf。
结果似乎有利于我最初的设计。至少这回答了问题。如果其他人有其他方法,我很乐意看到。
I decided to create a test case on jsPerf.
The results seem to favor my original design. At least that answers the question. If anyone else has another method, I'd love to see it.