1

我有一个奇怪的问题:我有一个页面可以在除 IE11 之外的所有主要浏览器上正常工作,但页面无法加载。

我在ie 11的控制台中检查,发现这个错误:

在此处输入图像描述

错误是指设置滚动条样式的函数 SetStyle:

class ScrollBarStyle{
  init(){
    return{
      setStyle: this._setStyle
    }
  }
  _setStyle(node,color,targetClass){
    let self = this;
    let children = Array.from(node.children); // I have set Array.from polifyll for ie11
    if(children){
      children.forEach(function(el){
        if(el.classList.contains(targetClass)){
            el.style.width = '10px';
            el.style.background = color;
            el.style.opacity = '1'
            return
        }
        self.setStyle(el,color,targetClass)
        })      
      }
    }
  }

这是我用来以这种方式设置滚动条样式的函数:

  _initMainScrollBar(){
    let self = this;
    this.contents.forEach(function(cnt){
      let ps = self.createScrollBar(cnt); //using perfect scrollbar plugin
      let color = self._RetrieveScrollBarColor(cnt)[0]; // get the main color of a section
      self.scrollBarStyle.setStyle(cnt,color,self.targetClass) //set the style
    })
  }

我不知道可能是什么问题,此代码在其他浏览器中有效,我还没有找到有关 ie11 和this关键字的有用信息。

显然似乎做var n=thisn 结果是不确定的,

老实说,我不知道可能是什么问题。

我正在使用 babel 和 gulp:

gulp.task('js',()=>{
  return browserify({
    entries: ['./src/js/main.js'],
    debug:true
   })
  .bundle()
  .pipe(source('bundle.js'))
  .pipe(buffer())
  .pipe(babel({
    presets: ['env'],
    compact: true
  }))
  .pipe(uglify())
  .pipe(gulp.dest('./src/dist/js/'))
  .pipe(browserSync.stream());
});

而且我还为 ie11 插入了Array.frompolyfill,所以我认为这不是问题所在

有人可以给我一些关于这个问题的提示吗?也许与完美滚动条插件有关?

4

0 回答 0