var $menu = $('.menu'),
$items = $menu.find('li'),
num = $items.length,
current = -1;
$(document).on('keyup', function (e) {
var key = e.which;
switch (key) {
case 38:
current--;
if (current < 0) {
current = num - 1;
}
break;
case 40:
current++;
if (current > num - 1) {
current = 0;
}
break;
};
$items.eq(current).addClass('active').siblings().removeClass('active');
});
var max = 1000;
if (x < 0) {
x = max;
} else if (x > max) {
x = 0;
}
.container {
position: relative;
width: 400px;
height: 400px;
overflow: hidden;
border: 1px solid #000;
}
.scroll {
position: relative;
box-sizing: border-box;
width: 420px;
max-height: 400px;
padding-right: 20px;
overflow-y: scroll;
}