0
我在水平佈局中工作,並嘗試使用jquery在單擊錨點時,在html部分中導航。所以當點擊跳轉到下一節。跳轉到下一部分 - jquery
我看到一些相同但垂直的例子!
的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>
我做錯了什麼?
這是一個基本的錯誤! :)我認爲scrollTo是一個jQuery方法!感謝charlietfl;) – Mysteriis