navBar.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view>
  3. <scroll-view scroll-y="true" class="scroll" @scroll="scrollChnage">
  4. <view class="navbar-section" :class="{'navbar-fixed-section': isFixed}">
  5. <ss-scroll-navbar :tabCurrentIndex="currentIndex" @navbarTap="navbarTapHandler" :scrollChangeIndex="currentI"
  6. :navArr="navList"></ss-scroll-navbar>
  7. </view>
  8. </scroll-view>
  9. </view>
  10. </template>
  11. <script>
  12. import ssScrollNavbar from '@/components/navBar/scroll-navbar.vue'
  13. export default {
  14. props: ['currentI', 'navList'],
  15. components: {
  16. ssScrollNavbar
  17. },
  18. data() {
  19. return {
  20. currentIndex: 0,
  21. isFixed: false,
  22. topHeight: 0,
  23. listData: [],
  24. }
  25. },
  26. onLoad(options) {
  27. // uni.setNavigationBarTitle({
  28. // title: options.title
  29. // });
  30. this.calculateTopSectionHeight();
  31. },
  32. created() {},
  33. methods: {
  34. navbarTapHandler(index) {
  35. this.currentIndex = index;
  36. this.$emit('currentIndex', index)
  37. },
  38. scrollChnage(e) {
  39. let top = e.detail.scrollTop;
  40. if (top >= this.topHeight) {
  41. this.isFixed = true;
  42. } else {
  43. this.isFixed = false;
  44. }
  45. },
  46. /**
  47. * 计算头部视图的高度
  48. */
  49. calculateTopSectionHeight() {
  50. var that = this;
  51. let topView = uni.createSelectorQuery().select(".top-section");
  52. topView.fields({
  53. size: true
  54. }, data => {
  55. that.topHeight = data.height;
  56. }).exec();
  57. }
  58. },
  59. watch: {
  60. currentI: function(newVal) {
  61. this.navbarTapHandler(newVal)
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss">
  67. .scroll {
  68. // position: absolute;
  69. // top: 0upx;
  70. // left: 0upx;
  71. // bottom: 0upx;
  72. // right: 0upx;
  73. // .navbar-fixed-section {
  74. // position: fixed;
  75. // top: 0upx;
  76. // left: 0upx;
  77. // right: 0upx;
  78. // }
  79. .top-section {
  80. height: 350upx;
  81. background-color: green;
  82. }
  83. .bottom-section {
  84. height: 1500upx;
  85. background-color: yellow;
  86. }
  87. .footer-section {
  88. height: 1500upx;
  89. background-color: blue;
  90. }
  91. }
  92. </style>