Skip to content

Commit

Permalink
Merge pull request #14 from l-hammer/bugfix_track_show
Browse files Browse the repository at this point in the history
🐛Fix track show be called when scrolling
  • Loading branch information
LHammer authored Aug 13, 2019
2 parents 68d2bba + 1c90ff9 commit 88cd175
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "v-track",
"version": "0.8.6",
"version": "0.8.7",
"description": "一个基于Vue指令的埋点插件",
"author": "LHammer <[email protected]>",
"scripts": {
Expand Down
9 changes: 7 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-20 18:34:33
* @Last Modified time: 2019-08-13 12:14:37
*/
import { isElement, isVisible, isInViewport } from "./dom";
import { isFun, debounce } from "./helper";
Expand All @@ -22,6 +22,7 @@ export default class VisMonitor {
this.ref = ref;
this.refWin = refwin;
this.started = false;
this.prevPerc = null; // 保存前一次曝光百分比
this.listeners = {};
this.removeScrollLisener = null;
this.init();
Expand Down Expand Up @@ -116,6 +117,7 @@ export default class VisMonitor {
const view = this.viewport();

if (!isInViewport(rect, view) || !isVisible(this.ele)) {
this.prevPerc = 0;
return 0;
}

Expand All @@ -134,7 +136,10 @@ export default class VisMonitor {
vw = Math.min(view.width, rect.right);
}
perc = (vh * vw) / (rect.height * rect.width);
if (perc === 1) this.$emit("fullyvisible");
if (this.prevPerc !== 1 && perc === 1) {
this.$emit("fullyvisible");
this.prevPerc = perc;
}
}

/**
Expand Down

0 comments on commit 88cd175

Please sign in to comment.