graceNavBar2.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <scroll-view scroll-with-animation
  3. :class="['grace-nav-bar2', isCenter ? 'grace-nav2-center' : '']" :scroll-x="true" :show-scrollbar="false"
  4. :scroll-into-view="'tab-'+currentIndex+autoLeft">
  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. autoLeft: {type : String, default : ''}
  40. },
  41. methods:{
  42. navchang : function (e){
  43. this.$emit('change', Number(e.currentTarget.dataset.index))
  44. }
  45. }
  46. }
  47. </script>
  48. <style scoped>
  49. /* #ifndef MP-ALIPAY */
  50. .grace-nav-bar2{width:100%; display:flex; white-space:nowrap;}
  51. /* #endif */
  52. /* #ifdef MP-ALIPAY */
  53. .grace-nav-bar2{width:100%; white-space:nowrap;}
  54. /* #endif */
  55. .nav2-item{width:100rpx; display:inline-flex; flex-direction:column; padding-bottom:16rpx; position:relative;}
  56. .nav2-item-title{width:100%; color:#333333; display:block; text-align:center;}
  57. .nav2-item-desc{width:100%; color:#666666; display:block; text-align:center; padding-bottom:6rpx;}
  58. .nav2-active{font-weight:bold;}
  59. .nav2-active-line-wrap{display:flex;}
  60. .grace-nav2-center{justify-content:center; text-align:center;}
  61. @keyframes grace-nav-fadein{0%{transform: scale(0,0);} 100%{transform: scale(1,1);}}
  62. .grace-nav-fadein{animation:grace-nav-fadein 300ms forwards;}
  63. .nav2-active-line-in{position:absolute; left:0; bottom:2rpx; z-index:1; display:flex; flex-direction:row; justify-content:center; width:100%;}
  64. .nav2-active-line{width:20rpx; height:20rpx; border-radius:50rpx; border:6rpx solid #FF0000;}
  65. .nav2-nav-body{position:absolute; z-index:2; left:0; top:0; width:100%;}
  66. </style>