【发布时间】:2012-12-23 06:59:05
【问题描述】:
这里是an example of what I have already
主要功能可以工作,但现在我需要缩小控制器列表,以便它更适合屏幕,因为它是固定位置的。
所以,我认为它应该显示来自活动项的下三个列表项和前两个列表项。
这样的事情会起作用,但我认为应该有更短更方便的方式:
//Display closest items
$('#historyController li.active').prevAll('li:not(.first)').hide().slice(0,2).show();
$('#historyController li.active').nextAll('li:not(.last)').hide().slice(0,3).show();
任何重构当前代码以获得更好性能的技巧也会有所帮助。
【问题讨论】:
-
Something like this would work, but I think there should be shorter and more convinient way或any tips for re-factoring current code for better performance would be helpful as well如果没有任何问题并且您的代码可以正常工作,但您只是在寻找替代或更好的方法,那么这个问题可能会在 Stackexchange - Code Review 上更好 -
不确定我是否完全理解,但“最接近”的方法是否对您有帮助:api.jquery.com/closest
标签: javascript jquery navigation html-lists