graceNavBar.vue 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <scroll-view scroll-with-animation
  3. :class="['grace-nav-bar', isCenter ? 'grace-nav-center' : '']" :scroll-x="true" :show-scrollbar="false"
  4. :scroll-into-view="'tab-'+currentIndex+autoLeft">
  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, fontWeight:currentIndex == index ? activeFontWeight : ''}">{{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. activeFontWeight: {type : Number, default : 700},
  35. margin : {type : Number, default : 0},
  36. textAlign : {type : String, default : ''},
  37. lineHeight :{type : String, default : '50rpx'},
  38. padding : {type : String, default : '0rpx'},
  39. animatie:{type:Boolean, default:true},
  40. autoLeft: {type : String, default : ''}
  41. },
  42. methods:{
  43. navchang : function (e){
  44. this.$emit('change', Number(e.currentTarget.dataset.index))
  45. }
  46. }
  47. }
  48. </script>
  49. <style scoped>
  50. /* #ifndef MP-ALIPAY */
  51. .grace-nav-bar{width:100%; display:flex; white-space:nowrap;}
  52. /* #endif */
  53. /* #ifdef MP-ALIPAY */
  54. .grace-nav-bar{width:100%; white-space:nowrap;}
  55. /* #endif */
  56. .nav-item{width:100rpx; display:inline-flex; flex-direction:column;}
  57. .nav-item-title{width:100%; color:#333333;}
  58. .nav-active{}
  59. .nav-active-line-wrap{display:flex;}
  60. .nav-active-line{margin-top:5rpx;}
  61. .grace-nav-center{justify-content:center; text-align:center;}
  62. @keyframes grace-nav-scale{0%{transform: scale(0.1);} 100%{transform: scale(1);}}
  63. .grace-nav-scale{animation:grace-nav-scale 300ms forwards;}
  64. </style>