```
document.addEventListener('visibilitychange', () => {
? ? ? if (document.hidden === true) {
? ? ? ? // 頁(yè)面被掛起
? ? ? ? clearInterval(timer);
? ? ? } else {
? ? ? ? // 頁(yè)面由掛起被激活
? ? ? ? if (this.parameBtn) {
? ? ? ? ? let tempLeft = 0;
? ? ? ? ? clearInterval(timer);
? ? ? ? ? // 滾動(dòng)定時(shí)器
? ? ? ? ? timer = setInterval(() => {
? ? ? ? ? ? if (tempLeft <= this.boxW * -1) {
? ? ? ? ? ? ? // 消失在視野后 從后面進(jìn)入繼續(xù)滾動(dòng)
? ? ? ? ? ? ? tempLeft = 290;
? ? ? ? ? ? }
? ? ? ? ? ? tempLeft += -1;
? ? ? ? ? ? this.parameBtnLeft = tempLeft;
? ? ? ? ? }, 10);
? ? ? ? }
? ? ? }
? ? });
```
一個(gè)簡(jiǎn)單的標(biāo)題跑馬燈??
當(dāng)頁(yè)面切換的時(shí)候 ,清除定時(shí)器
頁(yè)面切回時(shí)凝赛,重啟定時(shí)器
解決切換頁(yè)面時(shí)定時(shí)間累計(jì)及停止的問題