|
@@ -79,6 +79,14 @@ export default { |
|
@@ -79,6 +79,14 @@ export default { |
79
|
yasOP: { // 用于监测点击事件的名称
|
79
|
yasOP: { // 用于监测点击事件的名称
|
80
|
type: String,
|
80
|
type: String,
|
81
|
default: ''
|
81
|
default: ''
|
|
|
82
|
+ },
|
|
|
83
|
+ parentHeight: { // 如果有父级元素包含此组件,请传递屏幕高度
|
|
|
84
|
+ type: Number,
|
|
|
85
|
+ default: 0
|
|
|
86
|
+ },
|
|
|
87
|
+ needParent: {
|
|
|
88
|
+ type: Boolean,
|
|
|
89
|
+ default: false
|
82
|
}
|
90
|
}
|
83
|
},
|
91
|
},
|
84
|
data() {
|
92
|
data() {
|
|
@@ -135,6 +143,7 @@ export default { |
|
@@ -135,6 +143,7 @@ export default { |
135
|
mounted() {
|
143
|
mounted() {
|
136
|
console.log('mounted');
|
144
|
console.log('mounted');
|
137
|
this.checkLogin();
|
145
|
this.checkLogin();
|
|
|
146
|
+ // console.log('scrollParent=', this.scrollParent);
|
138
|
},
|
147
|
},
|
139
|
methods: {
|
148
|
methods: {
|
140
|
loadMore() {
|
149
|
loadMore() {
|
|
@@ -145,12 +154,12 @@ export default { |
|
@@ -145,12 +154,12 @@ export default { |
145
|
this.scrollTop = this.$refs.waterfall.scrollTop;
|
154
|
this.scrollTop = this.$refs.waterfall.scrollTop;
|
146
|
this.$refs.waterfallComp.emitLoadMore();
|
155
|
this.$refs.waterfallComp.emitLoadMore();
|
147
|
|
156
|
|
148
|
- let containerHeight = this.$refs.waterfall.offsetHeight; // 容器高度
|
157
|
+ let containerHeight = this.needParent ? this.parentHeight : this.$refs.waterfall.offsetHeight; // 容器高度
|
149
|
let headerHeight = document.querySelector('.header') ? document.querySelector('.header').offsetHeight : 0; // 头部高度
|
158
|
let headerHeight = document.querySelector('.header') ? document.querySelector('.header').offsetHeight : 0; // 头部高度
|
150
|
|
159
|
|
151
|
this.scrollHandler({containerHeight: containerHeight, scrollTop: this.scrollTop, headerHeight: headerHeight});
|
160
|
this.scrollHandler({containerHeight: containerHeight, scrollTop: this.scrollTop, headerHeight: headerHeight});
|
152
|
},
|
161
|
},
|
153
|
- scrollHandler({containerHeight, scrollTop, headerHeight}) {
|
162
|
+ scrollHandler({containerHeight, scrollTop, headerHeight, containerOffsetTop}) {
|
154
|
if (this.timeout) {
|
163
|
if (this.timeout) {
|
155
|
clearTimeout(this.timeout);
|
164
|
clearTimeout(this.timeout);
|
156
|
this.timeout = null;
|
165
|
this.timeout = null;
|
|
@@ -158,7 +167,7 @@ export default { |
|
@@ -158,7 +167,7 @@ export default { |
158
|
|
167
|
|
159
|
let items = document.querySelectorAll('.cell-item:not(.collect)');
|
168
|
let items = document.querySelectorAll('.cell-item:not(.collect)');
|
160
|
|
169
|
|
161
|
- items.forEach((item) => { // 遍历元素,判断在可视区域的元素加上collect并加入上报数组,此方法不可重复曝光
|
170
|
+ items.forEach((item, index) => { // 遍历元素,判断在可视区域的元素加上collect并加入上报数组,此方法不可重复曝光
|
162
|
let isCollected = /collect/.test(item.className);
|
171
|
let isCollected = /collect/.test(item.className);
|
163
|
let bounding = item.getBoundingClientRect();
|
172
|
let bounding = item.getBoundingClientRect();
|
164
|
|
173
|
|
|
@@ -167,7 +176,7 @@ export default { |
|
@@ -167,7 +176,7 @@ export default { |
167
|
item.className += ' collect';
|
176
|
item.className += ' collect';
|
168
|
|
177
|
|
169
|
let yasParam = Object.assign({}, this.yasParams, {
|
178
|
let yasParam = Object.assign({}, this.yasParams, {
|
170
|
- I_INDEX: item.dataset.index,
|
179
|
+ I_INDEX: parseInt(item.dataset.index, 10) + 1,
|
171
|
ARTICLE_ID: item.dataset.id
|
180
|
ARTICLE_ID: item.dataset.id
|
172
|
});
|
181
|
});
|
173
|
|
182
|
|
|
@@ -191,7 +200,11 @@ export default { |
|
@@ -191,7 +200,11 @@ export default { |
191
|
|
200
|
|
192
|
},
|
201
|
},
|
193
|
isVisible(top, scrollTop, containerHeight, headerHeight) { // 判断元素是否在可视区域
|
202
|
isVisible(top, scrollTop, containerHeight, headerHeight) { // 判断元素是否在可视区域
|
|
|
203
|
+ if (this.needParent && !this.parentHeight) {
|
|
|
204
|
+ return false;
|
|
|
205
|
+ }
|
194
|
if (top - headerHeight > 0 && (top - headerHeight) < containerHeight - 100) {
|
206
|
if (top - headerHeight > 0 && (top - headerHeight) < containerHeight - 100) {
|
|
|
207
|
+ // console.log(top, scrollTop, containerHeight, headerHeight, (top-headerHeight));
|
195
|
return true;
|
208
|
return true;
|
196
|
} else {
|
209
|
} else {
|
197
|
return false;
|
210
|
return false;
|