我有(Joomla)一个带有以下元素的网页;Jquery Loading CSS之后
<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,谢谢。 –