improve navigating in typeahead menu

This commit is contained in:
Uwe Steinmann 2024-04-01 11:35:37 +02:00
parent da664f2948
commit f4a44a853f

View File

@ -157,10 +157,13 @@
, next = active.next() , next = active.next()
if (!next.length) { if (!next.length) {
next = $(this.$menu.find('li')[0]) next = $(this.$menu.find(this.options.itemtag)[0])
} }
next.addClass('active') next.addClass('active')
var index = this.$menu.children().index(next)
var r = this.$menu.height()/next.height()-1;
this.$menu.scrollTop(this.$menu.scrollTop()+next.offset().top-50-index*r)
} }
, prev: function (event) { , prev: function (event) {
@ -168,10 +171,13 @@
, prev = active.prev() , prev = active.prev()
if (!prev.length) { if (!prev.length) {
prev = this.$menu.find('li').last() prev = this.$menu.find(this.options.itemtag).last()
} }
prev.addClass('active') prev.addClass('active')
var index = this.$menu.children().index(prev)
var r = this.$menu.height()/prev.height()-1;
this.$menu.scrollTop(this.$menu.scrollTop()+prev.offset().top-50-index*r)
} }
, listen: function () { , listen: function () {