如何創建兩個滾動瀏覽器到文章標題的按鈕(「next」和「prev」)?動畫滾動到下一個/上一個帖子
<div id="cycle-posts">
<a id="next" href="#next"></a>
<a id="prev" href="#prev"></a>
</div>
<article>My first post</article>
<article>My second post</article>
<article>My third post</article>
<article>My fourth post</article>
如果它是相關的:在前幾個之後,我的文章使用「無限滾動」加載。
這是我走到這一步,但它甚至還沒有接近:
$('#cycle-posts a').bind('click', function (e) {
$articles = $('article');
e.preventDefault();
var totalArticles = $articles.length;
if ($(this).attr("id") == "next") {
new_index = ++current_index;
} else if ($(this).attr("id") == "prev") {
new_index = --current_index;
}
if (new_index > totalArticles) {
new_index = 0;
}
$articles.removeClass('current').eq(new_index).addClass('current');
console.log(new_index+'/'+totalArticles);
// now scroll offset, find offset based on .current?
});