I am trying to work with a jQuery script that I found at http://marcgrabanski.com/articles/scrollto-next-article-button-jquery , which allows me to customize the "next" and "previous" buttons that scroll the user through the page from one article to another (or previous). The idea is that the button stays in a fixed position and clicks the button several times so that the user scrolls through the next article (or other item).
I have a page that scrolls horizontally, so I want to adapt the code so that instead of finding the top of each h2 in the container, it finds the left side of each h2 and scrolls the user horizontally rather than vertically. Here is the code I'm using:
jQuery(function($){ $('<div id="next_arrow">Next</div>') .prependTo("body") //append the Next arrow div to the bottom of the document .click(function(){ scrollTop = $(window).scrollTop(); $('#container h2').each(function(i, h2){ // loop through article headings h2top = $(h2).offset().top; // get article heading top if (scrollTop<h2top) { // compare if document is below heading $.scrollTo(h2, 800); // scroll to in .8 of a second return false; // exit function } }); }); });
Any help is greatly appreciated in advance. Thanks.
Jp
@paulGraffix, @ShankarSangoli and @esses thank you for your answers.
As a continuation of my last question, how can I limit scrolling to just horizontal scrolling?
If you click on the arrows at the top http://174.121.134.126/~methfree/ , the window will scroll vertically (as well as horizontally) if the browser window is small enough to scroll vertically. Is there a way to add scroll-x (or something like that) to the script to restrict horizontal scrolling only?
Thanks,
Jp
jPaul source share