我正在创建一个站点,并希望将这个站点中的一些内容合并到我的菜单中。 http://webdesign.tutsplus.com/tutorials/javascript-tutorials/create-a-sticky-navigation-header-using-jquery-waypoints/ 我真的很希望我的菜单栏根据该部分进行更改,但我是全新的到 javascript 并且遇到了一些麻烦。现在,它似乎不起作用。有什么建议么?谢谢!这是一些代码
<script language="javascript" type="text/javascript">
$(function() {
// Do our DOM lookups beforehand
var nav_container = $(".nav-container");
var nav = $("nav");
nav_container.waypoint({
handler: function(direction) {
nav_container.toggleClass('sticky', direction=='down');
}
var sections = $('section');
var navigation_links = $('nav a');
sections.waypoint({
handler: function(event, direction) {
// handler code
},
offset: '35%'
});
var active_section;
active_section = $(this);
if (direction === "up") active_section = active_section.prev();
var active_link = $('nav a[href="#' + active_section.attr("id") + '"]');
navigation_links.removeClass("selected");
active_link.addClass("selected");
});
$("li.nav-item").click(function() {
$("html, body").animate({
scrollTop: $($(this).children().attr("href")).offset().top + "px"}, {duration: 500, easing: "swing"
});
return false;
});
$(document).ready(function(){
$('img').click(function(){
// get the url of the picture we clicked
var url = $(this).attr('src');
// get the url of the large image
var bigUrl = $('.large-picture > img').attr('src');
// change the url of the big picture
$('.large-picture > img').attr('src', url);
$(this).attr('src', bigUrl);
});
});
});
</script>
这里的菜单栏是如下所示的菜单栏,它对应于整个 html 中导航导致跳转到的标记
<div class = 'nav-container'>
<nav>
<div id = 'nav-items-container'>
<ul class='nav-items'>
<li class='nav-item'><a href='#what'>what</a></li>
<li class='nav-item'><a href='#how'>how</a></li>
<li class='nav-item'><a href='#why'>why</a></li>
<li class='nav-item'><a href='#who'>who</a></li>
<li class='nav-item'><a href='#where'>where</a></li>
</ul>
</div>
</nav>
</div>
一个标记看起来像这样
<div class = 'mark' id = 'what'></div>
标签在每个标记之前和之后使用以设置导航将更改的所需部分