graceNavBar.vue 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <scroll-view
  3. :class="['grace-nav-bar', isCenter ? 'grace-nav-center' : '']" :scroll-x="true" :show-scrollbar="false"
  4. :scroll-into-view="'tab-'+currentIndex">
  5. <view class="nav-item" :id="'tab-'+index"
  6. :style="{width:size < 1 ? 'auto' : size+'rpx', marginRight:margin+'rpx', padding:'0rpx '+padding}"
  7. v-for="(item, index) in items" :key="index" @click="navchang" :data-index="index">
  8. <view :class="['nav-item-title', currentIndex == index ? 'nav-active' : '']"
  9. :style="{color:currentIndex == index ? activeColor : color, textAlign : textAlign, lineHeight:lineHeight, fontSize:currentIndex == index ? activeFontSize : fontSize}">{{item}}</view>
  10. <view class="nav-active-line-wrap" :style="{justifyContent:activeDirection}">
  11. <view class="nav-active-line" :class="[currentIndex == index && animatie ?'grace-nav-scale':'']"
  12. :style="{background:activeLineBg, width:activeLineWidth, height:activeLineHeight, borderRadius:activeLineRadius}"
  13. v-if="currentIndex == index"></view>
  14. </view>
  15. </view>
  16. </scroll-view>
  17. </template>
  18. <script>
  19. export default {
  20. props:{
  21. isCenter : {type : Boolean, default : false},
  22. currentIndex : {type : Number,default : 0},
  23. size : {type : Number, default : 120},
  24. fontSize : {type : String,default : '28rpx'},
  25. activeFontSize : {type : String, default : '28rpx'},
  26. items : {type : Array,default : function () {return []}},
  27. activeLineBg : {type : String,default : "linear-gradient(to right, #66BFFF,#3388FF)"},
  28. color : {type : String, default : "#333333"},
  29. activeColor:{type : String, default : "#333333"},
  30. activeLineHeight : {type : String, default : '6rpx'},
  31. activeLineWidth : {type : String, default : "36rpx"},
  32. activeLineRadius : {type : String, default : "0rpx"},
  33. activeDirection : {type : String, default : ""},
  34. margin : {type : Number, default : 0},
  35. textAlign : {type : String, default : ''},
  36. lineHeight :{type : String, default : '50rpx'},
  37. padding : {type : String, default : '0rpx'},
  38. animatie:{type:Boolean, default:true}
  39. },
  40. methods:{
  41. navchang : function (e){
  42. this.$emit('change', Number(e.currentTarget.dataset.index))
  43. }
  44. }
  45. }
  46. </script>
  47. <style scoped>
  48. /* #ifndef MP-ALIPAY */
  49. .grace-nav-bar{width:100%; display:flex; white-space:nowrap;}
  50. /* #endif */
  51. /* #ifdef MP-ALIPAY */
  52. .grace-nav-bar{width:100%; white-space:nowrap;}
  53. /* #endif */
  54. .nav-item{width:100rpx; display:inline-flex; flex-direction:column;}
  55. .nav-item-title{width:100%; color:#333333;}
  56. .nav-active{font-weight:bold;}
  57. .nav-active-line-wrap{display:flex;}
  58. .nav-active-line{margin-top:5rpx;}
  59. .grace-nav-center{justify-content:center; text-align:center;}
  60. @keyframes grace-nav-scale{0%{transform: scale(0.1);} 100%{transform: scale(1);}}
  61. .grace-nav-scale{animation:grace-nav-scale 300ms forwards;}
  62. </style>