Есть скрип каторый при скроле блоками по процентам задает класс.
Как выполнять срипт до класса актив
var ProgressScroll = function () {
var s = void 0;
var elsMap = document.getElementById('test').children;
var mapItemsPersent = [
{ roadPersent: 4, targetEl: elsMap[0]},
{ roadPersent: 8, targetEl: elsMap[1]},
{ roadPersent: 12, targetEl: elsMap[2]},
{ roadPersent: 16, targetEl: elsMap[3]},
{ roadPersent: 20, targetEl: elsMap[4]},
{ roadPersent: 24, targetEl: elsMap[5]},
{ roadPersent: 28, targetEl: elsMap[6]},
{ roadPersent: 32, targetEl: elsMap[7]},
{ roadPersent: 36, targetEl: elsMap[8]},
{ roadPersent: 53, targetEl: elsMap[15]},
{ roadPersent: 54.5, targetEl: elsMap[14]},
{ roadPersent: 60, targetEl: elsMap[13]},
{ roadPersent: 67, targetEl: elsMap[12]},
{ roadPersent: 70, targetEl: elsMap[11]},
{ roadPersent: 74, targetEl: elsMap[10]},
{ roadPersent: 80, targetEl: elsMap[9]},
{ roadPersent: 86, targetEl: elsMap[16]},
{ roadPersent: 90, targetEl: elsMap[17]},
{ roadPersent: 92, targetEl: elsMap[18]},
{ roadPersent: 96, targetEl: elsMap[19]},
{ roadPersent: 100, targetEl: elsMap[20]}
];
mapItemsPersent.sort(function (a, b) {
return a.roadPersent - b.roadPersent;
});
onScroll: function onScroll() {
s.scrollPosition = $(document).scrollTop();
ProgressScroll.requestTick();
var scrollPercentage = (document.documentElement.scrollTop + document.body.scrollTop) / (document.documentElement.scrollHeight - document.documentElement.clientHeight);
var persent = parseInt(scrollPercentage * 100);
var currentItemIndex = elementAtPersent(persent, mapItemsPersent);
var actIndex = mapItemsPersent[currentItemIndex].targetEl.classList.contains('active');
if (currentItemIndex !== -1) {
mapItemsPersent[currentItemIndex].targetEl.classList.add('current');
mapItemsPersent[currentItemIndex].targetEl.classList.remove('previous');
for (var i = currentItemIndex - 1; i >= 0; i--) {
mapItemsPersent[i].targetEl.classList.add('previous');
mapItemsPersent[i].targetEl.classList.remove('current');
console.log(mapItemsPersent[i])
}
for (var _i = currentItemIndex + 1; _i < mapItemsPersent.length; _i++) {
mapItemsPersent[_i].targetEl.classList.remove('current');
}
}
Crnm