trn-nav.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view>
  3. <view :style="'background:'+(propBackgroundColor || '#fff')+';'+nav_style" :class="'trn-nav-top '+(propEnt || '')">
  4. <view v-if="(propTitle || null) != null" class="trn-nav-top-title single-text">{{propTitle}}</view>
  5. <slot></slot>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. const app = getApp();
  11. export default {
  12. data() {
  13. return {
  14. statusbar_height: 0,
  15. nav_style: ''
  16. }
  17. },
  18. props: {
  19. propTitle: String,
  20. propBackgroundColor: String,
  21. propEnt: String,
  22. propScroll: Number,
  23. propHeight: Number,
  24. },
  25. watch: {
  26. // 属性值改变监听
  27. propScroll(value, old_value) {
  28. // opacity 0 就是完全透明 1是不透明
  29. var opacity = 0;
  30. if(value >= 70 && value <= 100) {
  31. opacity = 0.2;
  32. }
  33. // 越往下滑动 透明度越低
  34. if(value >= 101 && value <= 120) {
  35. opacity = 0.3;
  36. }
  37. if(value >= 120 && value <= 150) {
  38. opacity = 0.5;
  39. }
  40. if(value >= 150 && value <= 170) {
  41. opacity = 0.7;
  42. }
  43. if(value >= 170 && value <= 190) {
  44. opacity = 1;
  45. }
  46. if(value > 190) {
  47. opacity = 1;
  48. }
  49. // 距离小于多少就不显示了
  50. if(value <= 70) {
  51. opacity = 0;
  52. }
  53. // 设置样式
  54. this.nav_style = 'opacity:'+opacity+';';
  55. // #ifdef MP
  56. this.nav_style += 'height:'+(this.propHeight+this.statusbar_height)+'rpx;';
  57. // #endif
  58. // #ifdef H5
  59. this.nav_style += 'height:44px;';
  60. // #endif
  61. }
  62. },
  63. methods: {
  64. },
  65. mounted() {
  66. // 获取系统状态栏高度
  67. this.statusbar_height = app.globalData.px_to_rpx(app.globalData.get_system_info('statusBarHeight', 0));
  68. }
  69. }
  70. </script>
  71. <style>
  72. .trn-nav-top {
  73. padding-top: var(--status-bar-height);
  74. opacity: 0;
  75. width: 100%;
  76. z-index: 10;
  77. position: fixed;
  78. top: 0;
  79. left: 0;
  80. }
  81. .trn-nav-top .trn-nav-top-title {
  82. font-size: 36rpx;
  83. text-align: left;
  84. padding: 12px 250rpx 0 20rpx;
  85. height: 37px;
  86. color: #000;
  87. }
  88. </style>