简体   繁体   English

单击向上和向下按钮时 UL LI 元素自动滚动 jQuery

[英]UL LI Element autoscroll when clicking Up and Down buttons jQuery

I im making channels editor, and i have problem of autoscrolling when third item is selected...so when user click on item 1 and click DOWN button three times it need to be this order: I im making channels editor, and i have problem of autoscrolling when third item is selected...so when user click on item 1 and click DOWN button three times it need to be this order:

3 4 1 3 4 1

And when user click UP button one time it needs to be this order:当用户单击 UP 按钮一次时,它需要是这个顺序:

1 2 3 1 2 3

So the idea is to scroll automatically if last item is in bottom...i need two automatically scrollers...one that scrolls when last item is in the list one item up and other scroller that is similar to previus scroller but to scrool in the middle of items.所以这个想法是在最后一项在底部时自动滚动......我需要两个自动滚动条......当最后一项在列表中时滚动一个项目向上滚动,另一个类似于previus滚动条但滚动的滚动条项目的中间。

I here is the code:我这里是代码:

enter code here http://jsfiddle.net/vtbymc8w/ enter code here http://jsfiddle.net/vtbymc8w/

EDIT:编辑:

I need to redefine my question because i wrong describe what i need to get:我需要重新定义我的问题,因为我错误地描述了我需要得到的东西:

Here is jsfiddle example:这是jsfiddle示例:

enter code here http://jsfiddle.net/vtbymc8w/3/ enter code here http://jsfiddle.net/vtbymc8w/3/

I need when user click on button down to move CH1 down and when it reaches to CH12 and one more is pressed down button it scrolls to position CH13.我需要当用户单击按钮向下移动 CH1 时,当它到达 CH12 并且再按下一个按钮时,它会滚动到 CH13 位置。

When user is for example on CH15 and start pressing up button CH15 is moving up when it reaches CH13 position and one more time is pressed up button it scrolls up.例如,当用户在 CH15 上并开始按下向上按钮时,CH15 在到达 CH13 位置时向上移动,再按一次向上按钮向上滚动。

This is classical windows scrollbar that scrolls up or down on every 13 item in list...i can't figure out how to do this in javascript or jquery (i think in css is impossible)...so if someone can give me clue or example how to get this to work.这是经典的 Windows 滚动条,它在列表中的每 13 个项目上向上或向下滚动......我不知道如何在 javascript 或 jquery 中做到这一点(我认为在 css 中是不可能的)......所以如果有人能给我线索或示例如何让这个工作。

Thanks谢谢

I think you need to use scrollTop .我认为您需要使用scrollTop Here my code I added:这是我添加的代码:

function handle(el) {
    $('.users-list.channels').scrollTop(el.position().top);
}

Call it inside up/down click handler:在上/下点击处理程序中调用它:

$(/*up or down*/).on('click', function(e) {
    var $currentElement = $('.users-list.channels .selected');
    // move down or up...

    handle($currentElement);
});

JSFiddler: http://jsfiddle.net/vtbymc8w/1/ JSFiddler: http : //jsfiddle.net/vtbymc8w/1/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM