Is there a way to apply a specific style to the six previous and six next items of a list, while giving a different style to those outside of this range using only CSS? I am currently using a functional but redundant jQuery code for this purpose. Can the prev() or prevUntil() functions be specified with a numeric value, like prev(6) or next(6)? Or should I consider using slice() instead?
Below is the jQuery code snippet I am using (where $navigationLink/s refer to anchor links on the page).
if (!$navigationLink.parent().hasClass('sub-menu-current')) {
$navigationLinks.parent().removeClass('sub-menu-current');
$navigationLink.parent().addClass('sub-menu-current');
$('li').removeClass('sub-menu-previous-1');
$navigationLink.parent().prev().addClass('sub-menu-previous-1');
// code for other previous and next items left out for brevity...
$('li').removeClass('sub-menu-previous-6');
$navigationLink.parent().prev().prev().prev().prev().prev().prev().addClass('sub-menu-previous-6');
$('li').removeClass('sub-menu-next-6');
$navigationLink.parent().next().next().next().next().next().next().addClass('sub-menu-next-6');
}
Note: Ideally, the number of previous and next items to be styled should match the viewport, but this might be a more complex task to achieve compared to the current implementation.