swiperNavBar.vue 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <!--组件-->
  3. <scroll-view show-scrollbar scroll-x='false' scroll-with-animation
  4. :scroll-into-view=" 'tab-' + scrollIntoView"
  5. :style="{ height:currentSwiperHeight + 'rpx' }">
  6. <view class="swiperTab" v-for="(item,index) in swiperTabList" :key='index'
  7. :style="{ width:currentSwiperWidth,lineHeight:currentSwiperHeight + 'rpx' }"
  8. :id=" 'tab-' + index " @tap="CurrentTab(index,item)">
  9. <!--导航标题-->
  10. <text :style="{ color:swiperTabIdx == index ? swiperCurrentColor:swiperColor }">
  11. {{ item }}
  12. </text>
  13. <!--导航标题-->
  14. <!--线条-->
  15. <view class="swiperLine" v-show="currentSwiperLineShow">
  16. <view class="swiperLineActive"
  17. :class="[ swiperTabIdx == index && currentSwiperLineAnimatie ?'currentLine':'' ]"
  18. :style="{
  19. width:currentSwiperLineActiveWidth,
  20. height:currentSwiperLineActiveHeight,
  21. background:currentSwiperLineActiveBg
  22. }" v-if=" swiperTabIdx == index ">
  23. </view>
  24. </view>
  25. <!--线条-->
  26. </view>
  27. </scroll-view>
  28. </template>
  29. <script>
  30. export default{
  31. data(){
  32. return{
  33. }
  34. },
  35. onLoad() { },
  36. props:{
  37. scrollIntoView:{ type:Number },//设置哪个方向可滚动,则在哪个方向滚动到该元素
  38. swiperTabList:{ type:Array },//导航列表
  39. swiperTabIdx:{ type:Number },//导航对应列表下标
  40. swiperColor:{ type:String },//导航栏字体未选中前颜色
  41. swiperCurrentColor:{ type:String },//选中当前导航栏字体颜色
  42. currentSwiperWidth:{ type:String },//当前导航的宽度 % upx rpx px
  43. currentSwiperHeight:{ type:Number },//当前导航的高度度 rpx px
  44. currentSwiperLineShow:{ type:Boolean },//是否显示线条
  45. currentSwiperLineActiveWidth:{ type:String },//当前选中的导航栏线条的宽度
  46. currentSwiperLineActiveHeight:{ type:String },//当前选中的导航栏线条的高度度
  47. currentSwiperLineActiveBg:{ type:String },//当前选中的导航栏线条颜色
  48. currentSwiperLineAnimatie:{ type:Number },//当前选中的导航栏线条过渡效果
  49. },
  50. methods:{
  51. CurrentTab:function (index,item){
  52. this.$emit('change',index,item);
  53. },
  54. }
  55. }
  56. </script>
  57. <style>
  58. .swiperHead scroll-view{
  59. display: flex;
  60. flex-direction: row;
  61. flex-wrap: nowrap;
  62. white-space: nowrap;
  63. }
  64. .swiperTab{
  65. display: inline-flex;
  66. flex-direction: column;
  67. text-align: center;
  68. position: relative;
  69. }
  70. .swiperLine{ position: absolute;bottom:-10px;left: 0;width: 100%;z-index: 10; }
  71. .swiperLineActive{ margin: 0 auto;border-radius: 30upx; }
  72. @keyframes currentLine{
  73. 0%{
  74. transform: scale(0.5);
  75. }
  76. 100%{
  77. transform: scale(1);
  78. }
  79. }
  80. .currentLine{ animation:currentLine 300ms forwards; }
  81. </style>