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

View File

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