开发者

How to scroll to a particular <li>?

How can I send a user to a url where it will automatically scroll to a give开发者_开发问答n <li>?

E.g mysite.com/something.html#someItem

have him scroll to

<ul>
   <li id='someItem'>Something here</li>
</ul>


Exactly that.
Your code will work as-is.


There's plenty of examples of scrolling to (any) element using jQuery. There's even plugins that'll do it for you, like ScrollTo. :-)

If you want a (really) simple example, here it is:

function scrollTo(selector) {
    $('html, body').stop().animate({
        scrollTop: $(selector).offset().top
    }, 1000,'easeInOut');
}


You need an anchor tag. Like this:

<ul>
   <li id='someItem'>
       <a name='someItem'></a>
       Something here
   </li>
</ul>

Edit: markup

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜