|
| 1 | +import nodeUtil from '../core/utils/node-util'; |
1 | 2 | Component({ |
2 | | - externalClasses: ['l-class','l-icon-class'], |
| 3 | + externalClasses: ['l-class', 'l-icon-class'], |
3 | 4 |
|
4 | 5 | properties: { |
5 | 6 | type: { |
@@ -77,25 +78,22 @@ Component({ |
77 | 78 | }, |
78 | 79 |
|
79 | 80 | methods: { |
80 | | - initAnimation() { |
81 | | - wx.createSelectorQuery().in(this).select('.l-noticebar-content-wrap').boundingClientRect((wrapRect) => { |
82 | | - wx.createSelectorQuery().in(this).select('.l-noticebar-content').boundingClientRect((rect) => { |
83 | | - const duration = rect.width / 40 * this.data.speed; |
84 | | - const animation = wx.createAnimation({ |
85 | | - duration: duration, |
86 | | - timingFunction: 'linear', |
87 | | - }); |
88 | | - this.setData({ |
89 | | - wrapWidth: wrapRect.width, |
90 | | - width: rect.width, |
91 | | - duration: duration, |
92 | | - animation: animation |
93 | | - }, () => { |
94 | | - this.startAnimation(); |
95 | | - }); |
96 | | - }).exec(); |
97 | | - |
98 | | - }).exec(); |
| 81 | + async initAnimation() { |
| 82 | + const rect = await nodeUtil.getNodeRectFromComponent(this, '.l-noticebar-content'); |
| 83 | + const wrapRect = await nodeUtil.getNodeRectFromComponent(this, '.l-noticebar-content-wrap'); |
| 84 | + const duration = rect.width / 40 * this.data.speed; |
| 85 | + const animation = wx.createAnimation({ |
| 86 | + duration: duration, |
| 87 | + timingFunction: 'linear', |
| 88 | + }); |
| 89 | + this.setData({ |
| 90 | + wrapWidth: wrapRect.width, |
| 91 | + width: rect.width, |
| 92 | + duration: duration, |
| 93 | + animation: animation |
| 94 | + }, () => { |
| 95 | + this.startAnimation(); |
| 96 | + }); |
99 | 97 | }, |
100 | 98 | startAnimation() { |
101 | 99 | //reset |
@@ -126,18 +124,18 @@ Component({ |
126 | 124 | } |
127 | 125 | }, |
128 | 126 | handleTap() { |
129 | | - this.triggerEvent('lintap',{},{ bubbles: true, composed: true }); |
| 127 | + this.triggerEvent('lintap', {}, { bubbles: true, composed: true }); |
130 | 128 | this.setData({ |
131 | 129 | timer: null |
132 | 130 | }); |
133 | 131 | }, |
134 | 132 | onSwip(e) { |
135 | 133 | this.triggerEvent('lintap', { |
136 | 134 | ...e.currentTarget.dataset |
137 | | - },{ bubbles: true, composed: true }); |
| 135 | + }, { bubbles: true, composed: true }); |
138 | 136 | }, |
139 | | - onIconTap(){ |
140 | | - this.triggerEvent('linicontap',{},{ bubbles: true, composed: true }); |
| 137 | + onIconTap() { |
| 138 | + this.triggerEvent('linicontap', {}, { bubbles: true, composed: true }); |
141 | 139 | this.setData({ |
142 | 140 | timer: null |
143 | 141 | }); |
|
0 commit comments