I am working on an article carousel using jQuery to try to better strengthen the structure. I have a containing div, and in this div I have several articles.
<div id="container"> <article> <h3>Article Heading</h3> <p>Article Content</p> </article> <article> ... </div>
Div is formatted as a specific width and height, and overflow is hidden
I try to animate it, so when the user clicks the button, it calls a function to scroll through the next or previous article
var articles = -1; var currentPosition = -1; window.onload = function(){ articles = $("#container>article"); currentPosition = 0; } function scrollNext(){ $('#container').animate({ scrollTop: $(articles[currentPosition+1]).offset().top }, 750); currentPosition++; }
However, when the scrollNext function is called, it will scroll to the paragraph of the next article or will fail.
I am wondering if this is a problem with the selector, or perhaps with my page style, or what would be the right way to do this. See full page here.
Or try it on jsfiddle
source share