我正在尝试让页面顶部的导航栏保持透明,直到用户开始滚动,但是当页面加载时,会出现无样式的灰色。在用户向上滚动之前,透明性质不会激活。首次加载页面时,如何让导航栏保持透明,我需要做什么?
<div class="container">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#">AE</a>
</div>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="#">About Me</a>
<a href="#">My Life Before Code</a>
<a href="#">Portfolio</a>
<a href="#">Contact</a>
</li>
</ul>
</div>
</nav>
</div>
<div class="container-full-big">
<div class="jumbotron">
<h1>Hi. I'm Ashley.</h1>
</div>
</div>
.container-fluid {
height: 60px;
}
.navbar-default {
border: none;
}
.navbar-default .navbar-brand {
font-family: 'Lobster', cursive;
font-size: 30px;
color: #ffffff;
}
.navbar-default .navbar-nav>li>a {
float: left;
font-size: 20px;
color: #ffffff;
padding-top: 20px;
}
.jumbotron {
background: url("img/sunset.jpg") center center no-repeat;
font-family: 'Lobster', cursive;
color: #ffffff;
background-size: cover;
height: 100vh;
padding: 0;
}
$(window).scroll(function () {
if ($(window).scrollTop() > 50) {
$(".navbar-default").css("background", "#443e41");
} else {
$(".navbar-default").css("background", "transparent");
}
});
答案 0 :(得分:0)
您需要在transparent
$(document).ready()
代码部分
$(document).ready(function(){
$(".navbar-default").css("background", "transparent");
});
您也可以尝试$('window').load()
: -
$('window').load(function(){
$(".navbar-default").css("background", "transparent");
});