|
@@ -11,70 +11,60 @@ |
|
@@ -11,70 +11,60 @@ |
11
|
export default {
|
11
|
export default {
|
12
|
name: 'Exposure',
|
12
|
name: 'Exposure',
|
13
|
props: {
|
13
|
props: {
|
14
|
- viewRect: {
|
|
|
15
|
- type: Object,
|
|
|
16
|
- default() {
|
|
|
17
|
- return {
|
|
|
18
|
- top: 0,
|
|
|
19
|
- left: 0,
|
|
|
20
|
- bottom: 0,
|
|
|
21
|
- right: 0
|
|
|
22
|
- }
|
|
|
23
|
- }
|
|
|
24
|
- },
|
|
|
25
|
- itemClass: {
|
|
|
26
|
- type: String,
|
|
|
27
|
- default() {
|
|
|
28
|
- return 'exposure-item';
|
|
|
29
|
- }
|
|
|
30
|
- }
|
14
|
+ topClassName: String
|
31
|
},
|
15
|
},
|
32
|
data() {
|
16
|
data() {
|
33
|
return {
|
17
|
return {
|
|
|
18
|
+ viewArea: {
|
|
|
19
|
+ top: 0,
|
|
|
20
|
+ bottom: 0
|
|
|
21
|
+ }
|
34
|
};
|
22
|
};
|
35
|
},
|
23
|
},
|
36
|
watch: {
|
24
|
watch: {
|
37
|
},
|
25
|
},
|
38
|
methods: {
|
26
|
methods: {
|
39
|
- checkReport(evt, isInit) {
|
27
|
+ checkReport() {
|
40
|
let children = _.filter(this.$children, child => {
|
28
|
let children = _.filter(this.$children, child => {
|
41
|
return child.$options.name === 'ExposureItem'
|
29
|
return child.$options.name === 'ExposureItem'
|
42
|
});
|
30
|
});
|
43
|
|
31
|
|
44
|
- _.each(children, (item, index) => {
|
|
|
45
|
- const visible = this.isVisible(item.$el, this.$scrollEl);
|
|
|
46
|
-
|
|
|
47
|
-// if (visible && (this.componentStatus[index] !== visible || isInit)) {
|
|
|
48
|
-// this.report(component, index + 1);
|
|
|
49
|
-// }
|
|
|
50
|
-// this.componentStatus[index] = visible;
|
32
|
+ _.each(children, child => {
|
|
|
33
|
+ return child.record(this.isVisible(child.$el))
|
51
|
});
|
34
|
});
|
52
|
},
|
35
|
},
|
53
|
- report() {
|
|
|
54
|
-
|
|
|
55
|
- },
|
|
|
56
|
isVisible($el) {
|
36
|
isVisible($el) {
|
57
|
const rect = $el.getBoundingClientRect();
|
37
|
const rect = $el.getBoundingClientRect();
|
58
|
-// return ((parentRect.top >= rect.top && parentRect.top <= (rect.top + rect.height)) ||
|
|
|
59
|
-// ((parentRect.top + parentRect.height) >= rect.top && (parentRect.top + parentRect.height) <= (rect.top + rect.height)) ||
|
|
|
60
|
-// (rect.top >= parentRect.top && (rect.top + rect.height) <= (parentRect.top + parentRect.height)));
|
|
|
61
|
- }
|
|
|
62
|
|
38
|
|
|
|
39
|
+ return ((rect.top > this.viewArea.top && rect.top < this.viewArea.bottom) ||
|
|
|
40
|
+ rect.bottom > this.viewArea.top && rect.bottom < this.viewArea.bottom)
|
|
|
41
|
+ }
|
63
|
},
|
42
|
},
|
64
|
created() {
|
43
|
created() {
|
65
|
},
|
44
|
},
|
66
|
mounted() {
|
45
|
mounted() {
|
|
|
46
|
+ const filterRect = document.querySelector(`.${this.topClassName}`).getBoundingClientRect();
|
|
|
47
|
+
|
|
|
48
|
+ // 可见区域顶部距离视口的上边的距离
|
|
|
49
|
+ this.viewArea.top = filterRect.bottom;
|
|
|
50
|
+
|
|
|
51
|
+ // 可见区域底部距离视口的上边的距离
|
|
|
52
|
+ this.viewArea.bottom = window.screen.height;
|
|
|
53
|
+
|
67
|
this.$scrollEl = window;
|
54
|
this.$scrollEl = window;
|
68
|
this.scrollEvent = util.throttle(500, this.checkReport);
|
55
|
this.scrollEvent = util.throttle(500, this.checkReport);
|
69
|
if (this.$scrollEl) {
|
56
|
if (this.$scrollEl) {
|
70
|
this.$scrollEl.addEventListener('scroll', this.scrollEvent);
|
57
|
this.$scrollEl.addEventListener('scroll', this.scrollEvent);
|
71
|
- this.checkReport(void 0, true);
|
|
|
72
|
- }
|
|
|
73
|
|
58
|
|
|
|
59
|
+ let timer = setInterval(() => {
|
|
|
60
|
+ if (this.$children.length) {
|
|
|
61
|
+ clearInterval(timer);
|
|
|
62
|
+ this.checkReport(void 0, true);
|
|
|
63
|
+ }
|
|
|
64
|
+ }, 500);
|
|
|
65
|
+ }
|
74
|
setInterval(() => {
|
66
|
setInterval(() => {
|
75
|
- let children = _.filter(this.$children, child => child.$options.name === 'ExposureItem');
|
|
|
76
|
- _.each(children, child => child.report());
|
|
|
77
|
- this.report();
|
67
|
+ _.each(_.filter(this.$children, child => child.$options.name === 'ExposureItem'), child => child.report());
|
78
|
}, 3000);
|
68
|
}, 3000);
|
79
|
}
|
69
|
}
|
80
|
};
|
70
|
};
|