gpt4 book ai didi

jquery - 更改滚动条上 Bootstrap 导航栏的颜色

转载 作者:行者123 更新时间:2023-11-28 05:28:23 34 4
gpt4 key购买 nike

我知道有很多关于此的问题,但似乎没有一个答案对我有用。我正在尝试编写一些 jquery 来让我的 Bootstrap 导航栏在有人滚动传递元素后改变颜色。有人可以告诉我我做错了什么。谢谢!

Github 链接:https://github.com/Sruthik22/Sruthik22.github.io jquery 在头部

    <!DOCTYPE html>
<html lang = "en">
<head>
<meta charset="utf-8">
<title>Sruthi Kurada</title>
<meta name="description" content="Sruthi Kurada's Personal Website">
<meta name="author" content="Sruthi Kurada">
<!-- CSS Stylesheets -->
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="bootstrap/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">
<link rel="stylesheet" href="style.css">

<script type="text/javascript">
$(document).ready(function(){
var scroll_start = 0;
var startchange = $('#Home');
var offset = startchange.offset();
if (startchange.length){
$(document).scroll(function() {
scroll_start = $(this).scrollTop();
if(scroll_start > offset.top) {
$('nav.navbar-custom').css('background-color', '#f0f0f0');
} else {
$('nav.navbar-custom').css('background-color', 'transparent');
}
});
}
});
</script>
</head>
<body>
<nav class="navbar navbar-fixed-top navbar-custom">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#Home">Sruthi Kurada</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<div class="nav navbar-nav navbar-right">
<a class="navbar-brand nav-elements page-scroll" href="#Home">Home</a>
<a class="navbar-brand nav-elements page-scroll" href="#About">About</a>
<a class="navbar-brand nav-elements page-scroll" href="#Skills">Skills</a>
<a class="navbar-brand nav-elements page-scroll" href="#Portfolio">Portfolio</a>
<a class="navbar-brand nav-elements page-scroll" href="#Contact">Contact</a>
</div>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<a name = "Home" id = "Home"></a>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
<li data-target="#carousel-example-generic" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<div class="item active">
<img src="Images/Robotics.jpg" alt="FLL Robotics Robot">
<div class="carousel-caption">
<h1>Innovator</h1>
</div>
</div>
<div class="item">
<img src="Images/Math.jpg" alt="Math on a chalkboard">
<div class="carousel-caption">
<h1>Math Enthusiast</h1>
</div>
</div>
<div class="item">
<img src="Images/PythonCode.png" alt="Python Code on Computer">
<div class="carousel-caption">
<h1>Coder</h1>
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!--About Me-->
<a name="About" id = "About"></a>
<div class = "About">
<div class="container">
<br>
<div id="sruthi-picture"></div>
<div class="row">
<div class = "col-md-1 col-xs-1"></div>
<div class="col-md-10 col-xs-10 text-center" id="Intro">
My name is Sruthi Kurada
</div>
<div class = "col-xs-1"></div>
</div>
<div class="row">
<div class = "col-xs-1"></div>
<div class="col-xs-10 text-center" id = "Subtitle">
I am a 7th Grader at the Advanced Math & Science Academy (AMSA).
</div>
</div>
<br>
<div class="row">
<div class = "col-xs-1"></div>
<div class="col-xs-10 text-center" id = "about-descript">
I am interested in Robotics, Math, and Coding. I participate in FLL a Lego Robotics Competition. I do many mathamatics competitions, and I have coded several Python and Java Projects.
</div>
</div>
<div class="row">
<div class = "col-xs-1"></div>
<div class="col-xs-10 text-center" id = "about-descript">
I enjoy designing technology for less fortunate people and recently designed a belt to help the blind. I also play basketball & do karate as extracuriculars.
</div>
</div>
<br>
</div>
</div>
<div class = "AMSA">
<div class="row">
<div class = "col-xs-1"></div>
<div class="col-xs-10 text-center vcenter" id = "amsaText">
<p>My school the Advanced Math and Science Academy is where I participate in many activities with my friends.</p>
</div>
</div>
</div>
<a name="Skills"></a>
<div class="container">
<div class="row text-center">
<div class="col-lg-10 col-lg-offset-1">
<h2 id = "SkillsTitle">Skills</h2>
<div class="row">
<div class="col-md-3 col-sm-6">
<div class="service-item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-users fa-stack-1x text-primary portfolioIcon" aria-hidden="true"></i>
</span>
<h4>
<strong class = "PortfolioTextTitle">Leadership</strong>
</h4>
<br>
<p class = "PortfolioText"> Taught people on my FLL team how to build robots. Also have taught kids how to code</p>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="service-item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-android fa-stack-1x text-primary portfolioIcon" aria-hidden="true"></i>
</span>
<h4>
<strong class = "PortfolioTextTitle">App Developement</strong>
</h4>
<br>
<p class = "PortfolioText"> Learning Android Development and currently working on Udacity Nanodegree </p>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="service-item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-code fa-stack-1x text-primary portfolioIcon" aria-hidden="true"></i>
</span>
<h4>
<strong class = "PortfolioTextTitle">Python</strong>
</h4>
<br>
<p class = "PortfolioText"> Well versed in Python Application Development as well as Django Framework. </p>
</div>
</div>
<div class="col-md-3 col-sm-6">
<div class="service-item">
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-code fa-stack-1x text-primary portfolioIcon" aria-hidden="true"></i>
</span>
<h4>
<strong class = "PortfolioTextTitle">Java</strong>
</h4>
<br>
<p class = "PortfolioText"> Proficent in Java Developement. Currently learning Machine Learning.</p>
</div>
</div>
</div>
<br>
</div>
</div>
</div>

<a name="Portfolio"></a>
<div class = "Portfolio">
<div class="row">
<div class = "col-md-1 col-xs-1"></div>
<div class="col-md-10 col-xs-10 text-center" id="PortfolioTitle">
Portfolio
</div>
<div class = "col-xs-1"></div>
</div>
<div class = "row">
<div class = "col-md-2 col-sm-0"></div>
<div class="col-md-4 col-sm-6">
<div class = "portfolio-box">
<a title = "Movie App Github Source Code" href = "https://github.com/Sruthik22/MoviesApp">
<img class = "img-portfolio img-responsive" src = "Images/PopularMovies.PNG"/>
<p class = "imagetext">Movies App</p>
<div class = "portfolio-box-caption">
<div class = "portfolio-box-caption-content">
<div class = "project-category text-faded">
Android Development
</div>
<div class = "project-name">
An Android app I created that lets users find most popular movies and the top rated movies. Once you click on a movie specific movie poster then it will give you more specific details such as movie title and release date.
</div>
</div>
</div>
</a>
</div>
</div>
<div class="col-md-4 col-sm-6">
<div class = "portfolio-box">
<a title = "Clash of the Math Titans Github Source Code" href = "https://github.com/Sruthik22/Clash-of-the-Math-Titans">
<img class = "img-portfolio img-responsive" src = "Images/ClashOfTheMathTitans.png" alt="Code of Clash of the Math Titans"/>
<p class = "imagetext">Clash of the Math Titans</p>
<div class = "portfolio-box-caption">
<div class = "portfolio-box-caption-content">
<div class = "project-category text-faded">
Code
</div>
<div class = "project-name">
At a Hackathon my teammate and I designed this python game that helps young children learn the Order of Operations by gamifying it.
</div>
</div>
</div>
</a>
</div>
</div>
<div class = "col-md-2 col-sm-0"></div>
</div>

<br>

<div class = "row">
<div class = "col-md-2 col-sm-0"></div>
<div class="col-md-4 col-sm-6">
<div class = "portfolio-box">
<a title = "Battleship Github Source Code" href = "#">
<img class = "img-portfolio img-responsive" src = "Images/Battleship.png" alt="The Battleship code"/>
<p class = "imagetext">Battleship</p>
<div class = "portfolio-box-caption">
<div class = "portfolio-box-caption-content">
<div class = "project-category text-faded">
Code
</div>
<div class = "project-name">
The game battleship coded in python. There is both a single player mode and a multiplayer mode. The game also has graphics with the help of the graphics module graphics.py
</div>
</div>
</div>
</a>
</div>
</div>

<div class="col-md-4 col-sm-6">
<div class = "portfolio-box">
<a title = "Movie App Github Source Code" href = "https://www.youtube.com/watch?v=ogvRFzNWM2w">
<img class = "img-portfolio img-responsive" src = "Images/BeltForTheBlind.PNG" alt="Picture of the Limits of what a Product like the Blind Belt could do"/>
<p class = "imagetext">Belt for the Blind</p>
<div class = "portfolio-box-caption">
<div class = "portfolio-box-caption-content">
<div class = "project-category text-faded">
Hardware
</div>
<div class = "project-name">
A product I designed along with another team mate that helps the blind traverse their surroundings. It guides the user by using a ultrasonic sensor and alerts the user by using a volume component on the side of the bot. We won 3rd place in ProjectCSGirls.
</div>
</div>
</div>
</a>
</div>
</div>

<div class = "col-md-2 col-sm-0"></div>
</div>
<br>
</div>

<a name="Contact"></a>
<div class = "Contact">
<div class="row">
<div class = "col-md-1 col-xs-1"></div>
<div class="col-md-10 col-xs-10 text-center">
<h1 id="ContactTitle">Contact</h1>
</div>
<div class = "col-xs-1"></div>
</div>
<div class = "row">
<div class = "col-md-4 col-sm-4"></div>
<div class = "col-md-1 col-sm-1">
<a target="_blank" href = "https://github.com/Sruthik22" class = "social"><i class="fa fa-github-square social"></i></a>
</div>
<div class="col-md-2 center col-sm-2">
<a target="_blank" href = "mailto:fllheroes638@gmail.com" class = "social"><i class="fa fa-envelope icon social"></i></a>
</div>
<div class = "col-md-1 col-sm-1">
<a target="_blank" href = "http://stackoverflow.com/users/5693112/sruthi-kurada" class = "social"><i class="fa fa-stack-overflow social"></i></a>
</div>
<div class = "col-md-4 col-sm-4"></div>
</div>
</div>
</body>
</html>

最佳答案

您只是将 background-color 应用于错误的元素。试试这个:

$(document).scroll(function() { 
scroll_start = $(this).scrollTop();
if(scroll_start > offset.top) {
$('nav.navbar-custom').css('background-color', '#f0f0f0');
} else {
$('nav.navbar-custom').css('background-color', 'transparent');
}
});

关于jquery - 更改滚动条上 Bootstrap 导航栏的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38647415/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com