向下滚动页面时如何使导航栏更改颜色? [英] How to make navigation bar change color when you scroll down the page?
本文介绍了向下滚动页面时如何使导航栏更改颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望导航栏透明,但是当您向下滚动页面时,它会变成红色.
I would like the navigation bar to be transparent but when you scroll down the page it changes to color red for example.
<div class="nav">
<div class="container">
<div class="logo">
<a href="#"><img src="RepublicSquare_logo.svg" style="height: 80px;"></a>
</div>
<div class="navMain">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Services</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
推荐答案
类似以下内容:
var a = $(".nav").offset().top;
$(document).scroll(function(){
if($(this).scrollTop() > a)
{
$('.nav').css({"background":"red"});
} else {
$('.nav').css({"background":"transparent"});
}
});
这篇关于向下滚动页面时如何使导航栏更改颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文