fix: skip elements if they dont have proper index

v1.18.x
Barış Soner Uşaklı 4 years ago
parent 9cde5105ad
commit c9c9dd2f9b

@ -225,16 +225,18 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
var middleOfViewport = scrollTop + (windowHeight / 2); var middleOfViewport = scrollTop + (windowHeight / 2);
var previousDistance = Number.MAX_VALUE; var previousDistance = Number.MAX_VALUE;
els.each(function () { els.each(function () {
var elIndex = parseInt($(this).attr('data-index'), 10);
if (elIndex >= 0) {
var distanceToMiddle = Math.abs(middleOfViewport - $(this).offset().top); var distanceToMiddle = Math.abs(middleOfViewport - $(this).offset().top);
if (distanceToMiddle > previousDistance) { if (distanceToMiddle > previousDistance) {
return false; return false;
} }
if (distanceToMiddle < previousDistance) { if (distanceToMiddle < previousDistance) {
index = parseInt($(this).attr('data-index'), 10) + 1; index = elIndex + 1;
previousDistance = distanceToMiddle; previousDistance = distanceToMiddle;
} }
}
}); });
var atTop = scrollTop === 0 && parseInt(els.first().attr('data-index'), 10) === 0; var atTop = scrollTop === 0 && parseInt(els.first().attr('data-index'), 10) === 0;

Loading…
Cancel
Save