我目前正在对自然而然PIE附件插件。
它通过的indexOf遍历所有文档CSS样式表,对CSS3属性的检查,然后调用PIE附上情况下,它开创任何当前选择的方法。
主循环是这样的:PIE.js低性能
for (var j = 0, length2 = styleSheet.rules.length; j < length2; j++) {
rule = styleSheet.rules[j];
// the replacedProperties is a simple array
// with string values for css properties - border-radius and so on
$.each(replacedProperties, function(index, property) {
if (rule.style.cssText.indexOf(property) !== -1) {
try {
$(rule.selectorText).each(function() {
PIE.attach(this);
});
} catch(e) { }
return false;
}
}
});
}
这实际上是相当缓慢的,跑起来在IE8和IE7一个CSS3重型页面上2秒。
问题是,我可以以某种方式改善此循环的性能吗?
PIE.js实际上会优化重复附件,因此检查PIE是否连接将不会执行任何操作。
而到$ .fn.detach标准支队技术可悲的是不与PIE工作(虽然我还没有尝试过的香草版)。
我会非常感谢任何答案。
你为什么要这么做? PIE自动执行。我更喜欢'pie.htc',这只能在IE中触发,并没有其他浏览器的附加请求。 – Christoph
但它只附带PIE.attach,不是吗? – opportunato
其原因是让设计人员和开发人员无需手动添加PIE附件类。 – opportunato