我知道有些人已经问过类似的问题,但我没有找到答案。对不起,如果我不应该这样做。
所以我正在学习Javascript,当我想做一些会缩小我的Navbar的东西时,我在我的控制台中出现了这个错误:SyntaxError:missing)在正式参数之后。
我搜索了很多但找不到任何解决方案...... 这是我的代码:
function HeightBackground(){
height = $(window).height();
$("#cover").css({
'height': height
})
}
function ShrinkNavbar(){
$(window).scroll(function({
if($window.scrollTop() > 50){
$("#navbar").removeClass('full');
$("#navbar").addClass('shrink');
}else{
$("#navbar").removeClass('shrink');
$("#navbar").addClass('full');
}
}))
}
$(document).ready(function(){
HeightBackground();
$(window).resize(function(){
HeightBackground();
})
$(window).scroll(function(){
ShrinkNavbar();
})
})
答案 0 :(得分:1)
scroll
ShrinkNavbar
事件中回调的结束位置在功能结束时太远了。参数列表从未正确关闭:
function ShrinkNavbar(){
$(window).scroll(function({ // <- here
// ...
})) // <- and here
}
这是固定版本:
function ShrinkNavbar(){
$(window).scroll(function(){
// ...
})
}
答案 1 :(得分:0)
function HeightBackground() {
height = $(window).height();
$("#cover").css({
'height': height
})
}
function ShrinkNavbar() {
$(window).scroll(function () {
if ($window.scrollTop() > 50) {
$("#navbar").removeClass('full');
$("#navbar").addClass('shrink');
} else {
$("#navbar").removeClass('shrink');
$("#navbar").addClass('full');
}
})
}
$(document).ready(function () {
HeightBackground();
$(window).resize(function () {
HeightBackground();
})
$(window).scroll(function () {
ShrinkNavbar();
})
})
这是新代码.....我希望它的工作
答案 2 :(得分:0)
这是我的HTML代码:
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href="https://fonts.googleapis.com/css?family=Oxygen" rel="stylesheet">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="js/app.js"></script>
</head>
<body>
<nav class="navbar full" id="navbar">
<div class="container">
<a href="#" class="navbar-logo">
<img src="img/logo.jpg">
</a>
<div class="navbar-menu">
<a href="" class="active">Home</a>
<a href="">Biography</a>
<a href="">News</a>
</div>
</div>
</nav>
<header id="cover">
<div class="bg-cover">
</div>
</header>
<section class="content">
</section>
</body>
</html>