sunui-navbar.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <scroll-view scroll-with-animation :class="['sunui-nav-bar sticky']"
  3. :scroll-x="true" :show-scrollbar="false" :scroll-into-view="'tab-'+currentIndex+autoLeft">
  4. <view style="height: 46px;display: flex;" class="">
  5. <view :class="['flex-column-center', currentIndex == index && animatie ?'sunui-nav-scale':'' ]" :id="'tab-'+index" style="width: calc(100% / 4)"
  6. v-for="(item, index) in items" :key="index" @click="navchang" :data-index="index">
  7. <view :class="['nav-public', currentIndex == index ? 'nav-active' : 'nav-item']">{{item.name}}
  8. </view>
  9. <view :class="['nav-line']" :style="{width: currentIndex == index ? 'calc(100% - 14px)' : '0px'}"></view>
  10. </view>
  11. </view>
  12. </scroll-view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. items: {
  18. type: Array,
  19. default: function() {
  20. return []
  21. }
  22. },
  23. isCenter: {
  24. type: Boolean,
  25. default: true
  26. },
  27. currentIndex: {
  28. type: Number,
  29. default: 0
  30. },
  31. size: {
  32. type: Number,
  33. default: 120
  34. },
  35. fontSize: {
  36. type: String,
  37. default: '28rpx'
  38. },
  39. activeFontSize: {
  40. type: String,
  41. default: '28rpx'
  42. },
  43. activeLineBg: {
  44. type: String,
  45. default: "linear-gradient(to right, #66BFFF,#3388FF)"
  46. },
  47. color: {
  48. type: String,
  49. default: "#000"
  50. },
  51. activeColor: {
  52. type: String,
  53. default: "#333333"
  54. },
  55. activeLineHeight: {
  56. type: String,
  57. default: '6rpx'
  58. },
  59. activeLineWidth: {
  60. type: String,
  61. default: "36rpx"
  62. },
  63. activeLineRadius: {
  64. type: String,
  65. default: "0rpx"
  66. },
  67. activeDirection: {
  68. type: String,
  69. default: ""
  70. },
  71. activeFontWeight: {
  72. type: Number,
  73. default: 700
  74. },
  75. margin: {
  76. type: Number,
  77. default: 0
  78. },
  79. textAlign: {
  80. type: String,
  81. default: ''
  82. },
  83. lineHeight: {
  84. type: String,
  85. default: '50rpx'
  86. },
  87. padding: {
  88. type: String,
  89. default: '0rpx'
  90. },
  91. animatie: {
  92. type: Boolean,
  93. default: true
  94. },
  95. autoLeft: {
  96. type: String,
  97. default: ''
  98. }
  99. },
  100. methods: {
  101. navchang: function(e) {
  102. console.log(e.currentTarget.dataset.index)
  103. this.$emit('change', Number(e.currentTarget.dataset.index))
  104. }
  105. }
  106. }
  107. </script>
  108. <style scoped>
  109. .sunui-nav-bar {
  110. width: 100%;
  111. display: flex;
  112. white-space: nowrap;
  113. background-color: #fff;
  114. justify-content: center;
  115. text-align: center;
  116. }
  117. .sticky {
  118. position: sticky;
  119. width: 100%;
  120. left: 0;
  121. top: 20px;
  122. }
  123. .nav-public {
  124. min-width: calc(100%);
  125. line-height: 44px;
  126. height: 44px;
  127. /*border: 1px solid red;*/
  128. box-sizing: border-box;
  129. font-size: 15px;
  130. color: #B2BCCB;
  131. }
  132. .nav-line {
  133. /*min-width: calc(100% - 14px);*/
  134. height: 2px;
  135. background: #33CEF0;
  136. transition: all 0.2s linear;
  137. }
  138. .nav-active {
  139. /*background-color: #BF1C2D;*/
  140. color: #33CEF0;
  141. /*border-bottom: 2px solid #33CEF0;*/
  142. }
  143. .nav-item {
  144. background-color: #FFFFFF;
  145. }
  146. @keyframes sunui-nav-scale {
  147. 0% {
  148. transform: scale(0.8);
  149. }
  150. 100% {
  151. transform: scale(1);
  152. }
  153. }
  154. .sunui-nav-scale {
  155. animation: sunui-nav-scale 500ms forwards;
  156. }
  157. </style>