开发者

jquery vertically scrolled menu (scrollTo ?)

I was wondering if it is possible to get menu like this: http://www.pitgroup.nl/over-ons/ (over ons menu on the left) but writing less code.

What I have is:

<div class="scrollmenu">
    <ul class="scrollframe">
        <li><a href="#">Tony Start - CEO</a></li>
        <li><a href="#">John Connor - Art Director</a></li>
        <li><a href="#">Samatha Carter - Designer</a></li>
        <li><a href="#">John Smith - Web developer</a></li>
        <li><a href="#">Matthew Smith - Web developer</a></li>
        <li><a href="#">John Doe - Web developer</a></li>
        <li><a href="#">Kim Lee - Web developer</a></li>
        <li><a href="#">Jason Stone - PHP programmer</a></li>
        <li><a href="#">Veronica Moore - SEO Specialist</a></li>
        <li><a href="#">Mandy Ovanova - Marketing Manager</a></li>
    </ul>
</div>

bit of css:

.开发者_StackOverflowscrollmenu {width:428px;border-left:1px solid #e4e4e4;border-right:1px solid #e4e4e4;height:132px;overflow:hidden;}
.scrollmenu ul {list-style:none;padding:0px;margin:0px;}
.scrollmenu ul li {display:block;}
.scrollmenu ul li a {display:block;height:32px;border-bottom:1px solid #e4e4e4;line-height:32px;padding:0px 0px 0px 15px;text-transform:uppercase;color:#484848;background:#f4f4f4;}
.scrollmenu ul li a:hover, .scrollmenu ul li a.current {background:#e4e4e4;}

it's a simpliest vertical list and now I would like it to behave like in the given link http://www.pitgroup.nl/over-ons/. I was searching for something like this for few hours but only scripts that I found was drop downs or similar menus but not behaving like on the over-ons page.

Could anybody please help, what should I read in the jquery documentation to make something like this. Or maybe some of you guys already have something like this ?

edit: click on the positions - you will see that whole list is moving down or up and this is the effect I need.


Is this OK?

Demo: http://jsfiddle.net/XN6VL/2/

Code:

$('.scrollmenu a').click(function() { 
    var ul = $(this).closest('ul'),
        len = ul.children().length,
        ix = $(this).parent().index(),
        c = 'selected',
        h = $(this).outerHeight();

    ix = ix < 2 ? 2 : ix > len - 3 ? len - 3 : ix;
    ul.animate({'marginTop': (2 - ix) * h});
    $(this).addClass(c).parent().siblings().children('.' + c).removeClass(c);
    return false; 
});


You'll just need a hover event handler that calls the animate function in jQuery. Something like this:

$(".scrollmenu li").hover( function() {

    $(this).animate({
        margin-left: '+=10',    //or whatever number of pixels you want         
      }, 600);

    }, function() {

        $(this).animate({
            margin-left: '-=10',             
          }, 600);

    });

});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜