如何实现这样的音乐进度条呢?
首先:定义一个进度条的组件,基本样式和html如下:
<div class="progress-bar" ref="progressBar">
<div class="bar-inner">
<div class="progress" ref="progress"></div>
<div class="progress-btn-wrapper" ref="progressBtn">
<div class="progress-btn"></div>
</div>
</div>
</div>
<style lang="stylus" scoped>
@import '~common/stylus/variable'
.progress-bar
height 30px
.bar-inner
position relative
top 13px
height 4px
background rgba(0, 0, 0, 0.3)
.progress
position absolute
height 100%
background $color-theme
.progress-btn-wrapper
position absolute
left -8px
top -13px
width 30px
height 30px
.progress-btn
position relative
top 7px
left 7px
box-sizing border-box
width 16px
height 16px
border 3px solid $color-text
border-radius 50%
background $color-theme
</style>
在父组件里面样式和html如下:
<div class="progress-wrapper">
<div class="time time-l">{{format(this.currentTime)}}</div>
<div class="progress-bar-wrapper">
<progress-bar :percent="percent"></progress-bar>
</div>
<div class="time time-r">{{format(currentSong.duration)}}</div>
</div>
.progress-wrapper
display: flex
align-items: center
width: 80%
margin: 0px auto
padding: 10px 0
.time
color: $color-text
font-size: $font-size-small
flex: 0 0 30px
// 不放大/不缩小/固定30px
line-height: 30px
width: 30px
&.time-l
text-align: left
&.time-r
text-align: right
.progress-bar-wrapper
flex: 1
逻辑的实现