String can';t调用数据属性中定义的函数

String can';t调用数据属性中定义的函数,string,function,scope,String,Function,Scope,我正在构建一个长滚动站点,希望在每个元素滚动时调用一个函数 我已经用索引实现了这一点,但我需要定义在data attrdata fn中调用的函数 但是我不知道你是怎么让它“着火”的?试过以下几件事 var scrollVis = function () { ... function sectionActivate(index, progress) { console.log("sectionActivate"); } // fir

我正在构建一个长滚动站点,希望在每个元素滚动时调用一个函数

我已经用索引实现了这一点,但我需要定义在data attr
data fn
中调用的函数

但是我不知道你是怎么让它“着火”的?试过以下几件事

  var scrollVis = function () {
    
    ...
  function sectionActivate(index, progress) {
      console.log("sectionActivate");
  }
  // fires when page is scrolled, index is used to get <section class="step" data-fn=str">
  chart.update = function (index, progress) {
        // 
        // console.log(index, progress);
        updateFunctions[index](progress);
        var tgt = document.querySelectorAll(".step")[index];
        var sectionFn = tgt.getAttribute("data-fn");
        //      <section class="step" data-fn="sectionActivate">
        // sectionFn(index, progress);
        // console.log(tgt, sectionFn);
        window.sectionFn(1, 2);
        var fnstring = "sectionActivate";
        var fnparams = [1, 2];
    
        // find object
        var fn = window[fnstring];
    
        // is object a function?
        if (typeof fn === "function") fn.apply(null, fnparams);
      };
    ...
    };
var scrollVis=函数(){
...
功能部分激活(索引、进度){
控制台日志(“部分激活”);
}
//当页面滚动时激发,索引用于获取