Reputation: 5791
I made a Q&A page. I'd like to click on the question and have the page scroll to the question using jQuery. What script do I use? Does anyone have an example I can learn from?
Upvotes: 1
Views: 2235
Reputation: 23098
Really late at the party. Using bookmarks is the simplest solution (DVK's answer), but scrolling can be done in a more fancy way with animate
:
$('html, body')
.animate({
// for fixed top div, you must substract its height from top
scrollTop: $("#jumpBookmark").offset().top;
},
// animation duration
500);
Upvotes: 0
Reputation: 18880
I'd suggest LocalScroll which I've used in the past and found very easy to implement.
Upvotes: 0
Reputation: 129519
In simple cases (depends on how you "made" your Q&A page), you don't even need JQuery or any JavaScript.
Simply mark your answers with a name tag (for example <A NAME="Answer11"/>
) and then have every question be wrapped into a link to correct tag, e.g. <LI><A HREF="#Answer11">Question 11</A>
.
Upvotes: 1