我正忙着创建一个缩放器,但在重新加载时,它首先从 100% 切换,直到加载 cookie 并将宽度设置为固定值:
//set width from cookie, unfortunately we need todo this on docready because #main-container is not done rendering -_-
var width = $.cookie("width");
// Set the user's selection for the left column
if (width != null) {
if (width == "fluid") {
alert("fluid!");
$('#main-container').addClass('width-fluid');
} else {
$('#main-container').addClass('width-fixed');
}
} else {
$('#main-container').addClass('width-fixed');
};
有什么想法吗?
谢谢
丹尼斯
最佳答案
只需将默认的 css 属性“height”和“width”设置为 0 内联或外部 css 文件,然后当加载 cookie 时,它会将其设置为您想要的值。
例如。内联默认CSS(在js影响它之前)
<element style="height:0px;width:0px;" />
我假设您正在处理 block 级元素(图像),如果不是,您可能还希望将该元素设置为“display:block”,以便它将尊重高度和宽度。
关于javascript - 设置 css 属性的最快方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4564118/