CSS Twitter引导程序覆盖JavaScript样式,因为它在脚本之后执行.最后如何执行脚本



所以我正在向父页面发布iframe消息。iframe的内容发送一条具有宽度和高度的POST消息,我在收到消息后获取这些消息来更改元素的样式。然而,每当我这样做时,twitter引导程序都会改变元素的风格(我只能假设这是一个时间问题)。

我尝试包装消息侦听器的功能,但代码始终无法执行。在这里:

window.addEventListener("message", function(event) {
window.onload = function() {
console.log("loaded");
var array = event.data.split(" ");
addStyle(document.getElementById("outer-frame-form"), 
['height', 'width', 'position', 'overflow'], 
[array[0],array[1],'relative','hidden'], 
true);
}
});
function addStyle(element, properties, values, important) {
// this will be run when the whole pa
var i;
var cssString = "";
for (var i=0; i<properties.length; i++)
{
//remove previously defined property
if (element.style.setProperty)
element.style.setProperty(properties[i], '');
else
element.style.setAttribute(properties[i], '');
cssString += properties[i] + ':' + values[i] + ((important) ? ' !important' : '') + '; '
console.log(properties[i]);
}
//insert the new style with all the old rules
element.setAttribute('style', element.style.cssText + " " + cssString);
}

在加载完所有css之后,我还可以用什么方法来等待并执行脚本,这样twitter引导程序就无法覆盖它了?谢谢

我认为您可能过于复杂了。在模板的某个地方,您将有一个heading标记——这是加载引导程序的地方。把你的CSS元标签放在下面——它的"级联样式表",所以最后一个优先

最新更新