开发者

How I make scrollbar auto-scroll to a item in table

I have a table开发者_JAVA百科 with scrollbar. How I make scrollbar auto-scroll to a item in table. .


optikalefxx helped me out with this. http://www.youtube.com/watch?v=S6pzabpUmoc

HTML

<p class="navigation">
    <h2><a href="#link1">Link 1</a> | <a href="#link2">Link 2</a> | <a href="#link3">Link 3</a> | <a href="#link4">Link 4</a></h2>
</p>

Javascript

$(function() {
    // catch all clicks on a tags
    $("a").click(function() {
        // check if has hash
        if(this.hash) {
            // get rid of the # sign
            var hash = this.hash.substr(1);

            // get the position of the <a name>
            var $toElement = $("a[name="+hash+"]");
            var toPosition = $toElement.position().top;

            // scroll/animate to that element
            $("body,html").animate({
                scrollTop : toPosition
            },1500,"easeOutExpo");

            // don't do the jump
            return false;
        }
    });

    if(location.hash) {
        var hash = location.hash;
        window.scroll(0,0);
        $("a[href="+hash+"]").click();
    }
});

Hope it helps you too.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜