2019-02-14 HTML5 visibilitychange 事件

```

document.addEventListener('visibilitychange', () => {

      if (document.hidden === true) {

        // 页面被挂起

        clearInterval(timer);

      } else {

        // 页面由挂起被激活

        if (this.parameBtn) {

          let tempLeft = 0;

          clearInterval(timer);

          // 滚动定时器

          timer = setInterval(() => {

            if (tempLeft <= this.boxW * -1) {

              // 消失在视野后 从后面进入继续滚动

              tempLeft = 290;

            }

            tempLeft += -1;

            this.parameBtnLeft = tempLeft;

          }, 10);

        }

      }

    });

```


一个简单的标题跑马灯  

当页面切换的时候 ,清除定时器

页面切回时,重启定时器

解决切换页面时定时间累计及停止的问题

你可能感兴趣的:(2019-02-14 HTML5 visibilitychange 事件)