navbarTransparent.vue 1.5 KB

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