Javascript 为什么';这个JQuery函数不能工作吗?(向下滚动时使导航栏透明)
我一直在学习教程。我无法理解为什么我的JQuery函数都不起作用。我向下滚动,什么也没发生。我的所有文件都已正确链接和引用。我试图改变javascript,所以滚动50px将改变不透明度,但仍然没有工作。请帮忙 谢谢你抽出时间 index.htmlJavascript 为什么';这个JQuery函数不能工作吗?(向下滚动时使导航栏透明),javascript,jquery,html,css,Javascript,Jquery,Html,Css,我一直在学习教程。我无法理解为什么我的JQuery函数都不起作用。我向下滚动,什么也没发生。我的所有文件都已正确链接和引用。我试图改变javascript,所以滚动50px将改变不透明度,但仍然没有工作。请帮忙 谢谢你抽出时间 index.html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" conte
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.1/css/all.min.css" integrity="sha256-mmgLkCYLUQbXn0B1SRqzHar6dCnv9oZFPEC1g1cwlkk=" crossorigin="anonymous" />
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" media="screen and (max-width: 768px)" href="css/mobile.css.css">
<link rel="stylesheet" media="screen and (min-width: 1100px)" href="css/widescreen.css">
<title>EdgeLedger Financial | Accounting & Investment</title>
</head>
<body>
<nav id="navbar">
<h1 class="logo">
<span class="text-primary">
<i class="fas fa-book-open"></i> Edge
</span>Ledger
</h1>
<ul>
<li class="a" href="#"><a>Home</a></li>
<li class="a" href="#"><a>What</a></li>
<li class="a" href="#"><a>Who</a></li>
<li class="a" href="#"><a>Contact</a></li>
</ul>
</nav>
<!-- Showcase-->
<header id="showcase">
<div class="showcase-content">
<h1 class="l-heading">
The Sky Is The Limit
</h1>
<p class="lead">
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Doloremque, quidem nostrum blanditiis eaque voluptatum dignissimos?
</p>
<a href="" id="what" class="btn">Read More</a>
</div>
</header>
<!-- Section: What We Do-->
<section id="what" class="bg-light py-1">
<div class="container">
<h2 class="m-heading text-center"><span class="text-primary">What</span> We Do</h2>
<div class="items">
<div class="item">
<i class="fas fa-university fa-2x"></i>
<div>
<h3>Investment Banking</h3>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto ex eius sed? Eius, accusamus nobis!</p>
</div>
</div>
<div class="item">
<i class="fas fa-book-reader fa-2x"></i>
<div>
<h3>Portfolio Management</h3>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto ex eius sed? Eius, accusamus nobis!</p>
</div>
</div>
<div class="item">
<i class="fas fa-pencil-alt fa-2x"></i>
<div>
<h3>Tax & Custodial</h3>
<p>Lorem ipsum dolor sit amet consectetur, adipisicing elit. Architecto ex eius sed? Eius, accusamus nobis!</p>
</div>
</div>
</div>
</div>
</section>
<!-- Section: Who We are-->
<section id="who">
<div class="who-img"></div>
<div class="who-text bg-dark p-2">
<h2 class="m-heading"><span class="text-primary">Who</span> We Are </h2><p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Accusantium sapiente fugiat ab minus, sunt amet itaque id cupiditate inventore tempora.</p>
<h3>Our Team</h3>
<ul class="list">
<li>Mark Smith: CEO</li>
<li>Shannon Johnson: CFO</li>
<li>John Corbit: Lead Accountant</li>
<li>Janet Williams: Investment Manager</li>
<li>Kara Jackson: Senior Accountant</li>
</ul>
</div>
</section>
<!-- Section: Clients-->
<section id="clients" class="py-1">
<div class="container">
<h2 class="m-heading text-center">
<span class="text-primary">Our</span>
Clients
</h2>
</div>
<div class="items py1">
<div><img src="./img/logos/logo1.png" alt="Client"></div>
<div><img src="./img/logos/logo2.png" alt="Client"></div>
<div><img src="./img/logos/logo3.png" alt="Client"></div>
<div><img src="./img/logos/logo4.png" alt="Client"></div>
<div><img src="./img/logos/logo5.png" alt="Client"></div>
</div>
</section>
<!-- Section: Contact-->
<section id="contact">
<div class="contact-form bg-primary p-2">
<h2 class="m-heading">Contact Us</h2>
<p>Please use the form below to contact us</p>
<form>
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" id="name" placeholder="Enter Name">
</div>
<div class="form-group">
<label for="name">Email</label>
<input type="email" name="email" id="email" placeholder="Enter Email">
</div>
<div class="form-group">
<label for="name">Phone Number</label>
<input type="text" name="phone" id="phone" placeholder="Enter Phone Number">
</div>
<div class="form-group">
<label for="message">Message</label>
<textarea name="name" id="name" width="100%" placeholder="Enter Message"></textarea>
</div>
<input type="submit" value="Send" class="btn btn-dark">
</form>
</div>
<div class="map">
</div>
</section>
<!-- Footer -->
<footer id="main-footer">
<div class="container">
<p>Copyright © 2020 EdgeLedger All Rights Reserved</p>
</div>
</footer>
<!-- JQuery CDN -->
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous">
</script>
<!-- Local JS File -->
<script src="js/main.js"></script>
<!-- Google Maps -->
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAWwjIowcgGZxjQzSS1VlE_PtwSPrN0XJs&callback=initMap"
async defer></script>
</body>
</html>
main.js
var map;
function initMap() {
const loc = { lat: 42.361145, lng: -71.057083 };
const map = new google.maps.Map(document.querySelector('.map'), {
zoom: 14,
center: loc
});
const marker = new google.maps. Marker({position: loc, map: map});
}
// Sticky menu background
window.addEventListener ('scroll', function() {
if (window.scrollY > 150) {
document.querySelector('#navbar')style.opacity = 0.2;
} else {
document.querySelector('#navbar').style.opacity = 1;
}
});
// Smooth Scrolling
$('#navbar a, .btn').on('click', function(event) {
if (this.hash !== '') {
event.preventDefault();
const hash = this.hash;
$('html, body').animate(
{
scrollTop: $(hash).offset().top - 100
},
800
);
}
});
此行中缺少一个点:
document.querySelector('#navbar')style.opacity = 0.2;
(在“样式”之前)您是否查看了浏览器开发人员控制台中是否有任何错误例如,
文档中缺少的
代码>将使您的代码不运行
document.querySelector('#navbar')style.opacity = 0.2;