Skip to content

Commit

Permalink
⚡support init run visibilitychange
Browse files Browse the repository at this point in the history
  • Loading branch information
宋慧武 committed Apr 17, 2019
1 parent 70b8df1 commit 0f2718b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/utils/vis-monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: 宋慧武
* @Date: 2019-04-08 11:13:34
* @Last Modified by: 宋慧武
* @Last Modified time: 2019-04-13 23:10:29
* @Last Modified time: 2019-04-17 22:56:13
*/
import { isElement, isVisible, isInViewport } from "./dom";
import { isFun, debounce } from "./helper";
Expand All @@ -28,14 +28,17 @@ export default class VisMonitor {

init() {
if (!this.started) {
const listener = debounce(this.visibilitychange.bind(this));

listener();
this.removeScrollLisener = (listener => {
if (this.ref) {
return this.ref.$on("scroll", listener);
} else {
window.addEventListener("scroll", listener, false);
return () => window.removeEventListener("scroll", listener, false);
}
})(debounce(this.visibilitychange.bind(this)));
})(listener);
this.started = true;
}
}
Expand Down

0 comments on commit 0f2718b

Please sign in to comment.