mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-05-29 09:49:16 +08:00
[bugfix] Noticebar: 修复元素查询返回空,导致报错的问题 (#130)
* change quota * 修复 noticebar 查询
This commit is contained in:
parent
9092f26dd4
commit
56605cc5f3
@ -1,4 +1,4 @@
|
||||
var ZanNoticeBar = {
|
||||
const ZanNoticeBar = {
|
||||
initZanNoticeBarScroll(componentId) {
|
||||
this.zanNoticeBarNode = this.zanNoticeBarNode || {};
|
||||
this.zanNoticeBarNode[`${componentId}`] = {
|
||||
@ -7,38 +7,53 @@ 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) => {
|
||||
currentComponent.wrapWidth = rect.width;
|
||||
if (currentComponent.wrapWidth < currentComponent.width) {
|
||||
var mstime = currentComponent.width / 40 * 1000;
|
||||
currentComponent.animation = wx.createAnimation({
|
||||
duration: mstime,
|
||||
timingFunction: 'linear'
|
||||
});
|
||||
currentComponent.resetAnimation = wx.createAnimation({
|
||||
duration: 0,
|
||||
timingFunction: 'linear'
|
||||
});
|
||||
this.scrollZanNoticeBar(componentId, mstime);
|
||||
}
|
||||
}).exec();
|
||||
} else {
|
||||
console.warn('页面缺少 noticebar 元素');
|
||||
}
|
||||
}).exec();
|
||||
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;
|
||||
currentComponent.animation = wx.createAnimation({
|
||||
duration: mstime,
|
||||
timingFunction: 'linear'
|
||||
});
|
||||
currentComponent.resetAnimation = wx.createAnimation({
|
||||
duration: 0,
|
||||
timingFunction: 'linear'
|
||||
});
|
||||
this.scrollZanNoticeBar(componentId, mstime);
|
||||
}
|
||||
})
|
||||
.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()
|
||||
|
@ -155,7 +155,7 @@ module.exports = {
|
||||
keywords: ['contact'],
|
||||
src: '联系人.svg',
|
||||
css: 'contact',
|
||||
'correct_contour_direction': true
|
||||
correct_contour_direction: true
|
||||
},
|
||||
{
|
||||
keywords: ['wechat'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user