我的網站是https://www.jordanstechworld.com/我的jQuery的不能正常工作
我試圖使它的地方,當我的「關於標題」的頂部是在大約視口的半路上,我的文字變成紅色。問題是我的文本一直都是紅色的。我花了數小時試圖找到特種部隊的解決方案,並嘗試了多種不同的東西。我用這對我的jQuery
$(document).on('scroll', function() {
if($(this).scrollTop() >= 300){
$('#about-title').css('color', 'red');
}
});
這裏是我的HTML:
<doctype html>
<html>
<head>
<title>Home - Jordan's Tech World</title>
<link type="text/css" rel="stylesheet" href="/css/style.css"/>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script src="https://use.fontawesome.com/affe0d5d11.js"></script>
<link href="https://fonts.googleapis.com/css?family=Lato|Roboto" rel="stylesheet">
<meta name="theme-color" content="#1F4F8E"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div id="main-hero">
<i id="side-toggle" class="fa fa-bars" aria-hidden="true"></i>
<div class="main-nav">
<ul>
<img id="nav-logo" src="./images/logo-small.png" alt="">
<li id="about-btn"><a href="about">About</a></li>
<li id="portfolio-btn"><a href="portfolio">Portfolio</a></li>
<li id="development-btn"><a href="development">Development</a></li>
<li id="login-btn"><a href="login"><i class="fa fa-user" aria-hidden="true"></i> Login</a></li>
</ul>
</div>
<div class="side-nav">
<i id="side-toggle-small" class="fa fa-times" aria-hidden="true"></i>
<ul>
<li id="side-about-btn"><a href="about">About</a></li>
<li id="side-portfolio-btn"><a href="portfolio">Portfolio</a></li>
<li id="side-development-btn"><a href="development">Development</a></li>
<li id="side-login-btn"><a href="login"><i class="fa fa-user" aria-hidden="true"></i> Login</a></li>
</ul>
</div>
<a href="https://www.jordanstechworld.com/"><img id="logo" src="./images/logo.png" alt="JTW Logo"></a>
</div>
<i id="scroll-arrow" class="fa fa-arrow-down" aria-hidden="true"></i>
<div id="content">
<h1 id="about-title">About Me</h1>
<div id="container">
<div id="left-box">
<p>I am a 17 year old Journeyman Web Developer, Java Developer, and gaming enthusiast. I started getting into HTML, CSS, and dabbling into JQuery slightly. I can make some pretty impressive looking things happen, given time.</p>
</div>
<div id="right-box">
<p>I am a 17 year old Journeyman Web Developer, Java Developer, and gaming enthusiast. I started getting into HTML, CSS, and dabbling into JQuery slightly. I can make some pretty impressive looking things happen, given time.</p>
</div>
</div>
</div>
<script>
$(document).on('scroll', function() {
if($(this).scrollTop() >= 300){
$('#about-title').css('color', 'red');
}
});
$(document).ready(function(){
$(window).bind('scroll', function() {
var scrollTop = $(window).scrollTop();
var elementOffset = $('#about-title').offset().top;
var currentElementOffset = (elementOffset - scrollTop);
console.log(currentElementOffset);
});
});
$(document).scroll(function(){
if($('#left-box').scrollTop() <= 406){
$('#left-box').addClass('slide');
console.log("Reached");
}
else {
$('#left-box').removeClass('slide');
}
});
$("#side-toggle").click(function() {
$('.side-nav').toggleClass('open');
});
$("#side-toggle-small").click(function() {
$('.side-nav').toggleClass('open');
});
$("#scroll-arrow").click(function() {
$('html, body').animate({
scrollTop: $("#content").offset().top - 150
}, 1500);
});
</script>
</body>
</html>
</doctype>
請創建工作撥弄,使我們可以單獨複製。 – scooterlord
@scooterlord https://jsfiddle.net/kjue9e1h/2/也許這將工作? –
已更新@scooterlord鏈接。 –