How can I create two buttons ("next" and "prev") that will scroll the browser to the article's title?
<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>
If it's relevant: after the first few, my articles are loaded in using "infinite scroll".
This is what I got so far, but it's not even close:
$('#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?
});