Represents the progress bar.
Since: 1.0.0
Attributes
| Name | Type | Default Value | Mandatory | Description |
|---|---|---|---|---|
| percent | number | 0 | No | Percentage. The value ranges from 0 to 100. |
| show-info | boolean | false | No | Whether to show the percentage on the right of the progress bar. |
| border-radius | number|string | 0 | No | Corner radius. |
| font-size | number|string | 16 | No | Font size of the percentage on the right. |
| stroke-width | number|string | 4 | No | Stroke width of the progress bar. |
| color | string | #0A59F7 | No | Color of the completed progress bar segment, which is the same as activeColor. |
| activeColor | string | #0A59F7 | No | Color of the completed progress bar segment. |
| backgroundColor | string | rgba(0,0,0,0.098) | No | Color of the remaining progress bar segment. |
| active | boolean | false | No | Animation of the progress bar moving from left to right. |
| active-mode | string | backwards | No | - backwards: The animation is played from the beginning. - forwards: The animation resumes from the last end position. Since: 1.0.3 |
| duration | number | 30 | No | Time required for a 1% increase in the progress, in milliseconds. |
| bindactiveend | eventhandle | - | No | Animation completion event. |
Example:
HXML file:
<view class="container">
<view class="page-body">
<view class="page-section">
<view style="padding: 0 40rpx" class="page-section-title">Dynamic setting</view>
<view class="page-section-spacing">
<progress
percent="{{percent}}"
show-info="{{showInfo}}"
border-radius="{{borderRadius}}"
font-size="{{fontSize}}"
stroke-width="{{strokeWidth}}"
color="{{color}}"
activeColor="{{activeColor}}"
backgroundColor="{{backgroundColor}}"
active="{{active}}"
active-mode="{{activeMode}}"
bindactiveend="activeEndEvent"
duration="{{duration}}"/>
</view>
<view class="page-section-setting">
<view class="page-section-title">set active-mode: animation playback mode.</view>
<view class="weui-cell weui-cell_input">
<input value="{{activeMode}}" bindchange="setActiveMode" placeholder="backwards/forwards"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set show-info: percentage displayed.</view>
<view class="weui-cell weui-cell_input">
<input value="{{showInfo}}" bindchange="setShowInfo" placeholder="true/false"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set active: animation of the progress bar moving from left to right.</view>
<view class="weui-cell weui-cell_input">
<input value="{{active}}" bindchange="setActive" placeholder="true/false"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set percent: percentage ranging from 0 to 100.</view>
<view class="weui-cell weui-cell_input">
<input class="weui-input" value="{{percent}}" bindblur="setPercent"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set border-radius: corner radius.</view>
<view class="weui-cell weui-cell_input">
<input type="text" value="{{borderRadius}}" bindblur="setBorderRadius"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set font-size: font size of the percentage on the right.</view>
<view class="weui-cell weui-cell_input">
<input type="text" value="{{fontSize}}" bindblur="setFontSize"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set stroke-width: stroke width of the progress bar.</view>
<view class="weui-cell weui-cell_input">
<input class="weui-input" value="{{strokeWidth}}" bindblur="setStrokeWidth"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set duration: time required for a 1% increase in the progress, in milliseconds.</view>
<view class="weui-cell weui-cell_input">
<input class="weui-input" value="{{duration}}" bindblur="setDuration"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set color: color of the completed progress bar segment.</view>
<view class="weui-cell weui-cell_input">
<input type="text" value="{{color}}" bindblur="setColor"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set activeColor: color of the selected progress bar segment.</view>
<view class="weui-cell weui-cell_input">
<input type="text" value="{{activeColor}}" bindblur="setActiveColor"/>
</view>
</view>
<view class="page-section-setting">
<view class="page-section-title">set backgroundColor: color of the remaining progress bar segment.</view>
<view class="weui-cell weui-cell_input">
<input type="text" value="{{backgroundColor}}" bindblur="setBackgroundColor"/>
</view>
</view>
</view>
</view>
</view> JavaScript file:
const dataNormalize = (str) => {
let json;
try {
json = JSON.parse(str);
} catch {
console.error('dataNormalize error');
}
const baseObject = {
[str]: json ? json : str,
'object': {},
'null': null,
'undefined': undefined,
'false': false
};
return baseObject[str];
};
Page({
data: {
showInfo: false,
active: true,
activeMode: 'backwards',
percent: 100,
borderRadius: 0,
fontSize: 16,
strokeWidth: 4,
duration: 30,
color: '#0A59F7',
activeColor: '#0A59F7',
backgroundColor: '#00000019'
},
setActiveMode(event) {
console.info('setActiveMode', event.detail.value);
this.setData({
activeMode: dataNormalize(event.detail.value)
});
},
setShowInfo(event) {
console.info('setShowInfo', event.detail.value);
this.setData({
showInfo: dataNormalize(event.detail.value)
});
},
setActive(event) {
console.info('setActive', event.detail.value);
this.setData({
active: dataNormalize(event.detail.value)
});
},
setPercent(event) {
console.info('setPercent', event.detail.value);
this.setData({
percent: dataNormalize(event.detail.value)
});
},
setBorderRadius(event) {
console.info('setBorderRadius', event.detail.value);
this.setData({
borderRadius: dataNormalize(event.detail.value)
});
},
setFontSize(event) {
console.info('setFontSize', event.detail.value);
this.setData({
fontSize: dataNormalize(event.detail.value)
});
},
setStrokeWidth(event) {
console.info('setStrokeWidth', event.detail.value);
this.setData({
strokeWidth: dataNormalize(event.detail.value)
});
},
setDuration(event) {
console.info('setDuration', event.detail.value);
this.setData({
duration: dataNormalize(event.detail.value)
});
},
setColor(event) {
console.info('setColor', event.detail.value);
this.setData({
color: dataNormalize(event.detail.value)
});
},
setActiveColor(event) {
console.info('setActiveColor', event.detail.value);
this.setData({
activeColor: dataNormalize(event.detail.value)
});
},
setBackgroundColor(event) {
console.info('setBackgroundColor', event.detail.value);
this.setData({
backgroundColor: dataNormalize(event.detail.value)
});
},
activeEndEvent(event) {
// Example of event.detail: {"curPercent":0}
console.info('An activeEnd event occurred in the progress component. Carried data: ', event.detail)
}
}); CSS file:
.page-section {
width: 100%;
margin-bottom: 60rpx;
}
.page-section-setting {
border-radius: 40rpx;
border: 1px solid #ccc;
margin: 20rpx 10rpx;
padding: 20rpx 0;
}
.page-section-title {
font-size: 32rpx;
margin-bottom: 10rpx;
padding: 20rpx;
font-weight: 800;
color: #0A59F7;
}
.swiper-item {
display: block;
height: 100%;
}
.view-example {
display: flex;
align-items: center;
justify-content: center;
width: 400rpx;
height: 300rpx;
margin: 0 auto;
padding: 20rpx;
border: 1px solid #ccc;
}
.bg-red {
background-color: red;
}
.bg-blue {
background-color: blue;
}
.bg-green {
background-color: green;
}
button {
margin-left: 40rpx;
}
switch {
margin-left: 40rpx;
}
.weui-cell_input {
background-color: rgba(0, 0, 0, 0.047);
margin: 0 40rpx;
}