Skip to content

Commit 88cd175

Browse files
author
LHammer
authored
Merge pull request #14 from l-hammer/bugfix_track_show
🐛Fix track show be called when scrolling
2 parents 68d2bba + 1c90ff9 commit 88cd175

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "v-track",
3-
"version": "0.8.6",
3+
"version": "0.8.7",
44
"description": "一个基于Vue指令的埋点插件",
55
"author": "LHammer <lhammer@qq.com>",
66
"scripts": {

src/utils/vis-monitor.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* @Author: 宋慧武
33
* @Date: 2019-04-08 11:13:34
44
* @Last Modified by: 宋慧武
5-
* @Last Modified time: 2019-04-20 18:34:33
5+
* @Last Modified time: 2019-08-13 12:14:37
66
*/
77
import { isElement, isVisible, isInViewport } from "./dom";
88
import { isFun, debounce } from "./helper";
@@ -22,6 +22,7 @@ export default class VisMonitor {
2222
this.ref = ref;
2323
this.refWin = refwin;
2424
this.started = false;
25+
this.prevPerc = null; // 保存前一次曝光百分比
2526
this.listeners = {};
2627
this.removeScrollLisener = null;
2728
this.init();
@@ -116,6 +117,7 @@ export default class VisMonitor {
116117
const view = this.viewport();
117118

118119
if (!isInViewport(rect, view) || !isVisible(this.ele)) {
120+
this.prevPerc = 0;
119121
return 0;
120122
}
121123

@@ -134,7 +136,10 @@ export default class VisMonitor {
134136
vw = Math.min(view.width, rect.right);
135137
}
136138
perc = (vh * vw) / (rect.height * rect.width);
137-
if (perc === 1) this.$emit("fullyvisible");
139+
if (this.prevPerc !== 1 && perc === 1) {
140+
this.$emit("fullyvisible");
141+
this.prevPerc = perc;
142+
}
138143
}
139144

140145
/**

0 commit comments

Comments
 (0)