navbarTransparent.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view :class="{navbarTran: true, active: active}" :style="{height: `${placeholderHeight}px`}">
  3. <view :style="{height: `${barHeight}px`, marginTop:`${barTop}px`}">
  4. <view class="right-icon">
  5. <view class="right-icon-left">
  6. <uni-icons type="back" color="#171715" size="24" @click="back"></uni-icons>
  7. </view>
  8. <view style="background-color:#7e7e7c; height: 36rpx;width:2rpx; "></view>
  9. <view class="right-icon-right">
  10. <text>{{title}}</text>
  11. </view>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default{
  18. name: "navbarTransparent",
  19. props:['title'],
  20. data(){
  21. return {
  22. barTop:0,
  23. barHeight:0,
  24. placeholderHeight:0,
  25. active:false,
  26. timer: 0
  27. }
  28. },
  29. onReady(){
  30. this.barTop = uni.getSystemInfoSync().statusBarHeight
  31. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  32. this.barHeight = menuButtonInfo.height + (menuButtonInfo.top - this.barTop) * 2
  33. this.placeholderHeight = this.barHeight + this.barTop
  34. },
  35. onHide(){
  36. clearInterval(this.timer)
  37. },
  38. methods:{
  39. back(){
  40. uni.navigateBack({
  41. fail:()=>{
  42. uni.switchTab({
  43. url: "/pages/index/index"
  44. })
  45. }
  46. })
  47. },
  48. }
  49. }
  50. </script>
  51. <style lang="scss" scoped>
  52. .navbarTran{
  53. z-index: 100;
  54. position: fixed;
  55. top: 0;
  56. // height: 100rpx;
  57. width: 100%;
  58. background-color: transparent;
  59. transition: 0.3s all;
  60. >view{
  61. display: flex;
  62. align-items: center;
  63. justify-content: flex-start;
  64. }
  65. text{
  66. color:#000;
  67. font-size: 32rpx;
  68. text-shadow: 0.1px 0.1px 0.2px #000;
  69. }
  70. &.active{
  71. background-color: #fff;
  72. }
  73. .right-icon{
  74. margin-left: 30rpx;
  75. width: 174rpx;
  76. height: 64rpx;
  77. background: rgba(255,255,255,0.6);
  78. border-radius: 50rpx;
  79. display: flex;
  80. align-items: center;
  81. justify-content: space-between;
  82. padding: 10rpx 15rpx;
  83. .right-icon-left{
  84. }
  85. .right-icon-right{
  86. }
  87. }
  88. }
  89. </style>