mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
parent
6967e202b4
commit
a61f765260
@ -89,18 +89,18 @@
|
|||||||
|
|
||||||
### Props
|
### Props
|
||||||
|
|
||||||
| 参数 | 说明 | 类型 | 默认值 |
|
| 参数 | 说明 | 类型 | 默认值 |
|
||||||
| ---------- | ---------------------------------------- | --------- | ---------- |
|
| --- | --- | --- | --- |
|
||||||
| mode | 通告栏模式,可选值为 `closeable` `link` | _string_ | `''` |
|
| mode | 通告栏模式,可选值为 `closeable` `link` | _string_ | `''` |
|
||||||
| text | 通知文本内容 | _string_ | `''` |
|
| text | 通知文本内容 | _string_ | `''` |
|
||||||
| color | 通知文本颜色 | _string_ | `#ed6a0c` |
|
| color | 通知文本颜色 | _string_ | `#ed6a0c` |
|
||||||
| background | 滚动条背景 | _string_ | `#fffbe8` |
|
| background | 滚动条背景 | _string_ | `#fffbe8` |
|
||||||
| left-icon | 左侧[图标名称](#/icon)或图片链接 | _string_ | - |
|
| left-icon | 左侧[图标名称](#/icon)或图片链接 | _string_ | - |
|
||||||
| delay | 动画延迟时间 (s) | _number_ | `1` |
|
| delay | 动画延迟时间 (s) | _number_ | `1` |
|
||||||
| speed | 滚动速率 (px/s) | _number_ | `50` |
|
| speed | 滚动速率 (px/s) | _number_ | `50` |
|
||||||
| scrollable | 是否开启滚动播放,内容长度溢出时默认开启 | _boolean_ | `true` |
|
| scrollable | 是否开启滚动播放,内容长度溢出时默认开启 | _boolean_ | `true` |
|
||||||
| wrapable | 是否开启文本换行,只在禁用滚动时生效 | _boolean_ | `false` |
|
| wrapable | 是否开启文本换行,只在禁用滚动时生效 | _boolean_ | `false` |
|
||||||
| open-type | 微信开放能力 | _string_ | `navigate` |
|
| open-type | 微信开放能力 | _string_ | `navigate` |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
@ -111,10 +111,11 @@
|
|||||||
|
|
||||||
### Slot
|
### Slot
|
||||||
|
|
||||||
| 名称 | 说明 |
|
| 名称 | 说明 |
|
||||||
| ---------- | -------------- |
|
| ---------- | ---------------------------------------- |
|
||||||
| left-icon | 自定义左侧图标 |
|
| - | 通知文本内容,仅在 `text` 属性为空时有效 |
|
||||||
| right-icon | 自定义右侧图标 |
|
| left-icon | 自定义左侧图标 |
|
||||||
|
| right-icon | 自定义右侧图标 |
|
||||||
|
|
||||||
### 外部样式类
|
### 外部样式类
|
||||||
|
|
||||||
|
@ -6,11 +6,7 @@ VantComponent({
|
|||||||
text: {
|
text: {
|
||||||
type: String,
|
type: String,
|
||||||
value: '',
|
value: '',
|
||||||
observer() {
|
observer: 'init',
|
||||||
wx.nextTick(() => {
|
|
||||||
this.init();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
mode: {
|
mode: {
|
||||||
type: String,
|
type: String,
|
||||||
@ -31,11 +27,7 @@ VantComponent({
|
|||||||
speed: {
|
speed: {
|
||||||
type: Number,
|
type: Number,
|
||||||
value: 50,
|
value: 50,
|
||||||
observer() {
|
observer: 'init',
|
||||||
wx.nextTick(() => {
|
|
||||||
this.init();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
scrollable: {
|
scrollable: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
@ -66,38 +58,44 @@ VantComponent({
|
|||||||
this.timer && clearTimeout(this.timer);
|
this.timer && clearTimeout(this.timer);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.init();
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
Promise.all([
|
requestAnimationFrame(() => {
|
||||||
getRect(this, '.van-notice-bar__content'),
|
Promise.all([
|
||||||
getRect(this, '.van-notice-bar__wrap'),
|
getRect(this, '.van-notice-bar__content'),
|
||||||
]).then((rects) => {
|
getRect(this, '.van-notice-bar__wrap'),
|
||||||
const [contentRect, wrapRect] = rects;
|
]).then((rects) => {
|
||||||
if (
|
const [contentRect, wrapRect] = rects;
|
||||||
contentRect == null ||
|
if (
|
||||||
wrapRect == null ||
|
contentRect == null ||
|
||||||
!contentRect.width ||
|
wrapRect == null ||
|
||||||
!wrapRect.width
|
!contentRect.width ||
|
||||||
) {
|
!wrapRect.width
|
||||||
return;
|
) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { speed, scrollable, delay } = this.data;
|
const { speed, scrollable, delay } = this.data;
|
||||||
|
|
||||||
if (scrollable || wrapRect.width < contentRect.width) {
|
if (scrollable || wrapRect.width < contentRect.width) {
|
||||||
const duration = (contentRect.width / speed) * 1000;
|
const duration = (contentRect.width / speed) * 1000;
|
||||||
|
|
||||||
this.wrapWidth = wrapRect.width;
|
this.wrapWidth = wrapRect.width;
|
||||||
this.contentWidth = contentRect.width;
|
this.contentWidth = contentRect.width;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.animation = wx.createAnimation({
|
this.animation = wx.createAnimation({
|
||||||
duration,
|
duration,
|
||||||
timingFunction: 'linear',
|
timingFunction: 'linear',
|
||||||
delay,
|
delay,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.scroll();
|
this.scroll();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
<view class="van-notice-bar__wrap">
|
<view class="van-notice-bar__wrap">
|
||||||
<view class="van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}" animation="{{ animationData }}">
|
<view class="van-notice-bar__content {{ !scrollable && !wrapable ? 'van-ellipsis' : '' }}" animation="{{ animationData }}">
|
||||||
{{ text }}
|
{{ text }}
|
||||||
|
<slot wx:if="{{ !text }}"></slot>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user