【发布时间】:2017-07-22 04:31:06
【问题描述】:
我有 (Joomla) 一个包含以下元素的网页;
<section id="sp-top-bar">
<!-- html content -->
</section>
<section id="sp-footer">
<!-- html content -->
</section>
-
#sp-top-bar的样式通过custom.css- 带有background-color: blue。 -
#sp-footer的样式通过template.css- 带有background-color: green。
我正在使用 jquery 来强制 #sp-top-bar 使用与 template.css 文件中为 #sp-footer 设置的背景颜色相同的背景颜色。 (我知道还有其他方法可以设置颜色,但我正在尝试使用 jquery,所以请多多包涵!).
这是我的 jquery 代码,可以使用。
jQuery(function ($) {
var brand = $('#sp-footer');
var bg = brand.css('background-color');
$("#sp-top-bar").css({
backgroundColor: bg
})
});
我的 jquery 代码在文档的 <head> 中,在我的 template.css 文件之后。
当我的页面加载时,#sp-top-bar 最初会闪烁蓝色一瞬间,然后成功变为#sp-footer 绿色。
我查看了源代码,我的 template.css 文件正在加载之前我的 jquery 代码 - 大概这是问题所在?
我可以做些什么来避免#sp-top-bar 中出现这种初始背景颜色闪烁?
谢谢
【问题讨论】:
-
您介意为此使用
css解决方案吗?或者您想使用script来实现它? -
@VilasKumkar 我想使用 jquery,谢谢。
标签: javascript jquery html css