V
V
Vladimir2016-08-02 17:29:06
JavaScript
Vladimir, 2016-08-02 17:29:06

Why doesn't Angular JS track controller variables when scrolling on mobile?

Sample code from the service

onScroll(){
    this.scrollAfterTouchListener('scroll');
  }

  onTouchStart(){
    this.scrollAfterTouchListener('touch');
  }

  srollAfterTouch(type){
    if (type === 'touch') this.touched = true;
    if (type === 'scroll' && this.touched){
      if ((window.scrollY - this.prevScrollValue) < -50 ){
        if (!this.direction || this.direction === "up") this.emit("touchscroll",'down');
        this.direction = 'down';
        this.prevScrollValue = window.scrollY
      }
      if ((window.scrollY - this.prevScrollValue) >50 ){
        if (!this.direction || this.direction === "down") this.emit("touchscroll",'up');
        this.direction = 'up';
        this.prevScrollValue = window.scrollY
      }
    }
  }

Code example in controller
listenChangeVisiblity() {

    services.get(this).scope.$watch(() => this.isVisible, (direction) => {
      console.log({"visiblity1":direction});
    });

    services.get(this).header.on('touchscroll', this.setVisiblityHandler);
  }

  setVisiblity(direction){
    this.isVisible = direction;
    console.log({"visiblity2":direction});
  }

The bottom line is that in the console, the visiblity2 event passes immediately after the start of the scroll, and visiblity1 when I stop scrolling.
How to deal with this, assign classes with native methods of the browser?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question