graceNavBar2.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <scroll-view
  3. :class="['grace-nav-bar2', isCenter ? 'grace-nav-center2' : '']" :scroll-x="true" :show-scrollbar="false"
  4. :scroll-into-view="'tab-'+currentIndex">
  5. <view class="nav2-item" :id="'tab-'+index" :style="{width:size+'rpx', height:(lineHeight+lineHeightSamll+6)+'rpx'}"
  6. v-for="(item, index) in items" :key="index" @click="navchang" :data-index="index">
  7. <view class="nav2-nav-body">
  8. <text :class="['nav2-item-title', currentIndex == index ? 'nav-active' : '']"
  9. :style="{
  10. color:currentIndex == index ? activeColor : color,
  11. lineHeight:lineHeight+'rpx', fontSize:currentIndex == index ? activeFontSize : fontSize,
  12. background:bgColor,
  13. fontWeight:currentIndex == index ? 'bold' : ''}">{{item.title}}</text>
  14. <text :class="['nav2-item-desc', currentIndex == index ? 'nav-active' : '']"
  15. :style="{color:currentIndex == index ? activeColor : descColor, lineHeight:lineHeightSamll+'rpx', fontSize:fontSizeSmall, background:bgColor}">{{item.desc}}</text>
  16. </view>
  17. <view class="nav2-active-line-in" :class="currentIndex == index ? 'grace-nav-fadein' : ''">
  18. <view class="nav2-active-line" :style="{borderColor:currentIndex == index ? activeColor : bgColor}"></view>
  19. </view>
  20. </view>
  21. </scroll-view>
  22. </template>
  23. <script>
  24. export default {
  25. props:{
  26. isCenter : {type : Boolean, default : false},
  27. currentIndex : {type : Number,default : 0},
  28. size : {type : Number, default : 138},
  29. fontSize : {type : String,default : '28rpx'},
  30. activeFontSize: {type : String,default : '30rpx'},
  31. lineHeight :{type : Number, default : 52},
  32. fontSizeSmall: {type : String,default : '22rpx'},
  33. lineHeightSamll :{type : Number, default : 28},
  34. items : {type : Array,default : function () {return []}},
  35. color : {type : String, default : "#333333"},
  36. descColor : {type : String, default : "#999999"},
  37. activeColor:{type : String, default : "#3688FF"},
  38. bgColor:{type : String, default : '#FFFFFF'}
  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-bar2{width:100%; display:flex; white-space:nowrap;}
  50. /* #endif */
  51. /* #ifdef MP-ALIPAY */
  52. .grace-nav-bar2{width:100%; white-space:nowrap;}
  53. /* #endif */
  54. .nav2-item{width:100rpx; display:inline-flex; flex-direction:column; padding-bottom:16rpx; position:relative;}
  55. .nav2-item-title{width:100%; color:#333333; display:block; text-align:center;}
  56. .nav2-item-desc{width:100%; color:#666666; display:block; text-align:center; padding-bottom:6rpx;}
  57. .nav2-active{font-weight:bold;}
  58. .nav2-active-line-wrap{display:flex;}
  59. .grace-nav2-center{justify-content:center; text-align:center;}
  60. @keyframes grace-nav-fadein{0%{transform: scale(0,0);} 100%{transform: scale(1,1);}}
  61. .grace-nav-fadein{animation:grace-nav-fadein 300ms forwards;}
  62. .nav2-active-line-in{position:absolute; left:0; bottom:2rpx; z-index:1; display:flex; flex-direction:row; justify-content:center; width:100%;}
  63. .nav2-active-line{width:20rpx; height:20rpx; border-radius:50rpx; border:6rpx solid #FF0000;}
  64. .nav2-nav-body{position:absolute; z-index:2; left:0; top:0; width:100%;}
  65. </style>