Is there a delay between the value in js and the value in the page when Mini Program bindscroll saves the value?

problem description

get the current height through the scroll event of bindscroll, and then compare it with the values in the array to set the current category on the left

the environmental background of the problems and what methods you have tried

clipboard.png

js

clipboard.png

related codes

/ / Please paste the code text below (do not replace the code with pictures)
scroll: function (t) {

var that =this;
var a = this.data.dataheith, e = this.data.catalogSelect;

  for (var o = t.detail.scrollTop, s = 0; s < a.length; sPP){
      if (o <= a[s]) {
        if(e !=a[s]){
          this.setData({
            scroll_top: o,
            catalogSelect: s,
            toType: "type" + (s - 2)
          });
          break;
        }

      }
  }
console.log(that.data.catalogSelect)
},

what result do you expect? What is the error message actually seen?

Why does the value stutter, which has been successfully agreed in js? how does the delay in html come out?


has been solved, and it is my own judgment that leads to a lot of setdata


I don't have a lot of setData. Why is this also the case

?
Menu