我在水平布局中工作,并尝试使用 jquery 在单击锚点时在 html 部分中导航。所以当点击跳转到下一节。
我看到一些例子做同样的但垂直!
HTML 代码:
<div id="main">
<div id="nav">
<a id="prev" class="prev"> prev </a>
<a id="next" class="next"> next </a>
</div>
<div class="content-container">
<div class="content">
<section id="about" class="panel">
<p>About content</p>
</section><!-- end about -->
<section id="event" class="panel">
<p>Event content</p>
</section><!-- end event -->
<section id="services" class="panel">
<p>Services content</p>
</section><!-- end services -->
</div><!-- end content -->
</div><!-- end content-container -->
</div><!-- end main -->
JS代码
<script src="jquery-1.6.min.js"></script>
<script type="text/javascript">
function scrollToPosition(element) {
if (element !== undefined) {
$("#main.content-container").scrollTo(element, 700, {
margin: true
});
}
}
$(function() {
var posts = $('.panel');
var position = 0; //Start Position
var next = $('#next');
var prev = $('#prev').hide();
next.click(function(evt) {
prev.show();
scrollToPosition(posts[position += 1]);
if (position === posts.length - 1) {
next.hide();
}
});
prev.click(function(evt) {
next.show();
scrollToPosition(posts[position -= 1]);
if (position === 0) {
prev.hide();
}
});
});
</script>
我做错了什么?