topbar.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view>
  3. <tui-navigation-bar splitLine @init="initNavigation" @change="opacityChange" :scrollTop="scrollTop" :title="title" :backgroundColor="backgroundColor" :color="color">
  4. <view class="tui-header-icon" :style="{ marginTop: top + 'px' }"><tui-icon name="arrowleft" :color="opacity > 0.85 ? color : backgroundColor" @click="back"></tui-icon></view>
  5. </tui-navigation-bar>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. name:"topbar",
  11. props: {
  12. title: {
  13. type: String,
  14. default: ''
  15. },
  16. color: {
  17. type: String,
  18. default: '#333'
  19. },
  20. backgroundColor: {
  21. type: String,
  22. default: '#fff'
  23. },
  24. //滚动条滚动距离
  25. scrollTop: {
  26. type: [Number, String],
  27. default: 0
  28. },
  29. },
  30. data() {
  31. return {
  32. top: 0, //标题图标距离顶部距离
  33. opacity: 0,
  34. scrollTop: 0.5,
  35. };
  36. },
  37. onPageScroll(e) {
  38. this.scrollTop = e.scrollTop;
  39. },
  40. methods: {
  41. initNavigation(e) {
  42. this.opacity = e.opacity;
  43. this.top = e.top;
  44. },
  45. opacityChange(e) {
  46. this.opacity = e.opacity;
  47. },
  48. back() {
  49. uni.navigateBack()
  50. },
  51. }
  52. }
  53. </script>
  54. <style>
  55. .tui-header-icon {
  56. width: 100%;
  57. position: fixed;
  58. top: 0;
  59. padding: 0 12rpx;
  60. display: flex;
  61. align-items: center;
  62. height: 32px;
  63. transform: translateZ(0);
  64. z-index: 99999;
  65. box-sizing: border-box;
  66. }
  67. </style>