开发者

Scroll to bookmark on same page using jQuery?

I made a Q&A page. I'd like to click on the question and have the page scro开发者_Python百科ll to the question using jQuery. What script do I use? Does anyone have an example I can learn from?


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>.


I'd suggest LocalScroll which I've used in the past and found very easy to implement.


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜