[bugfix] Noticebar: 修复元素查询返回空,导致报错的问题 (#130)

* change quota

* 修复 noticebar 查询
This commit is contained in:
Yao 2018-02-12 15:54:55 +08:00 committed by GitHub
parent 9092f26dd4
commit 56605cc5f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 42 additions and 27 deletions

View File

@ -1,4 +1,4 @@
var ZanNoticeBar = { const ZanNoticeBar = {
initZanNoticeBarScroll(componentId) { initZanNoticeBarScroll(componentId) {
this.zanNoticeBarNode = this.zanNoticeBarNode || {}; this.zanNoticeBarNode = this.zanNoticeBarNode || {};
this.zanNoticeBarNode[`${componentId}`] = { this.zanNoticeBarNode[`${componentId}`] = {
@ -7,11 +7,27 @@ var ZanNoticeBar = {
animation: null, animation: null,
resetAnimation: null resetAnimation: null
}; };
var currentComponent = this.zanNoticeBarNode[`${componentId}`];
wx.createSelectorQuery().select(`#${componentId}__content`).boundingClientRect((rect) => { const currentComponent = this.zanNoticeBarNode[`${componentId}`];
if (rect.width) { wx.createSelectorQuery()
.in(this)
.select(`#${componentId}__content`)
.boundingClientRect((rect) => {
if (!rect || !rect.width) {
console.warn('页面缺少 noticebar 元素');
return;
}
currentComponent.width = rect.width; currentComponent.width = rect.width;
wx.createSelectorQuery().select(`#${componentId}__content-wrap`).boundingClientRect((rect) => { wx
.createSelectorQuery()
.in(this)
.select(`#${componentId}__content-wrap`)
.boundingClientRect((rect) => {
if (!rect || !rect.width) {
return;
}
currentComponent.wrapWidth = rect.width; currentComponent.wrapWidth = rect.width;
if (currentComponent.wrapWidth < currentComponent.width) { if (currentComponent.wrapWidth < currentComponent.width) {
var mstime = currentComponent.width / 40 * 1000; var mstime = currentComponent.width / 40 * 1000;
@ -25,20 +41,19 @@ var ZanNoticeBar = {
}); });
this.scrollZanNoticeBar(componentId, mstime); this.scrollZanNoticeBar(componentId, mstime);
} }
}).exec(); })
} else { .exec();
console.warn('页面缺少 noticebar 元素'); })
} .exec();
}).exec();
}, },
scrollZanNoticeBar(componentId, mstime) { scrollZanNoticeBar(componentId, mstime) {
var currentComponent = this.zanNoticeBarNode[`${componentId}`]; const currentComponent = this.zanNoticeBarNode[`${componentId}`];
var resetAnimationData = currentComponent.resetAnimation.translateX(currentComponent.wrapWidth).step(); const resetAnimationData = currentComponent.resetAnimation.translateX(currentComponent.wrapWidth).step();
this.setData({ this.setData({
[`${componentId}.animationData`]: resetAnimationData.export() [`${componentId}.animationData`]: resetAnimationData.export()
}); });
var aninationData = currentComponent.animation.translateX(-mstime * 40 / 1000).step(); const aninationData = currentComponent.animation.translateX(-mstime * 40 / 1000).step();
setTimeout(() => { setTimeout(() => {
this.setData({ this.setData({
[`${componentId}.animationData`]: aninationData.export() [`${componentId}.animationData`]: aninationData.export()

View File

@ -155,7 +155,7 @@ module.exports = {
keywords: ['contact'], keywords: ['contact'],
src: '联系人.svg', src: '联系人.svg',
css: 'contact', css: 'contact',
'correct_contour_direction': true correct_contour_direction: true
}, },
{ {
keywords: ['wechat'], keywords: ['wechat'],