当前位置:   article > 正文

小程序自定义头部导航栏(“navigationStyle“: “custom“),自定义tabBar_navigationstyle": "custom

navigationstyle": "custom

一、自定义顶部导航

1.在某些时候,不想要自带的顶部导航栏,需要自己定义,这时可以将自定义的导航栏做成一个组件,然后做一下初始配置,在每个页面引用,初始化,即可得到一个自定义的顶部导航栏;

2.代码部分

2.1首先在app.json的window中配置"navigationStyle": "custom"(使用自定头部导航栏)

2.2导航栏组件部分

(1)custom-component.wxml

  1. <!-- 组件 custom-component.wxml -->
  2. <custom-component>
  3. <view class='flex commonHead' style='color:{
  4. {myProperty.color?myProperty.color:"#000"}};background-color:{
  5. {myProperty.bg_color?myProperty.bg_color:"white"}};height:{
  6. {commonHeadHeight.titleHeight}}px;'>
  7. <view class='commonHead-wrap flex'>
  8. <!-- 0:无返回;1:返回上一级;2:home -->
  9. <view class='commonHead_left'>
  10. <view wx:if="{
  11. {myProperty.flag==1}}" class='commonHead_left_back' bindtap='commonHead_left_back'></view>
  12. <view wx:if="{
  13. {myProperty.flag==2}}" class='commonHead_left_home' bindtap='commonHead_left_home'></view>
  14. </view>
  15. <view class='commonHead_right flex'>
  16. <view class='commonHead_right_text line1'>{
  17. {myProperty.name?myProperty.name:"我是标题"}}</view>
  18. </view>
  19. </view>
  20. </view>
  21. </custom-component>

(2)custom-component.wxss

  1. /*弹性布局*/
  2. .flex {
  3. display: -webkit-box;
  4. display: -moz-box;
  5. display: -ms-flexbox;
  6. display: -webkit-flex;
  7. display: flex;
  8. display: box;
  9. flex-wrap: wrap;
  10. }
  11. .noWarp {
  12. flex-wrap: nowrap;
  13. }
  14. /*元素居中*/
  15. .alignC {
  16. align-items: center;
  17. -webkit-box-align: center;
  18. -webkit-align-items: center;
  19. -moz-align-items: center;
  20. -ms-align-items: center;
  21. -o-align-items: center;
  22. }
  23. /*水平排列*/
  24. .flexH {
  25. -webkit-box-orient: horizontal;
  26. -webkit-flex-direction: row;
  27. -moz-flex-direction: row;
  28. -ms-flex-direction: row;
  29. -o-flex-direction: row;
  30. flex-direction: row;
  31. }
  32. /*垂直排列*/
  33. .flexV {
  34. -webkit-box-orient: vertical;
  35. -webkit-flex-direction: column;
  36. -moz-flex-direction: column;
  37. -ms-flex-direction: column;
  38. -o-flex-direction: column;
  39. flex-direction: column;
  40. }
  41. /*两端对齐*/
  42. .flexSa {
  43. -webkit-box-pack: justify;
  44. justify-content: space-around;
  45. -webkit-justify-content: space-around;
  46. -moz-justify-content: space-around;
  47. -ms-justify-content: space-around;
  48. -o-justify-content: space-around;
  49. }
  50. /*居中对齐*/
  51. .flexC {
  52. -webkit-box-pack: center;
  53. justify-content: center;
  54. -webkit-justify-content: center;
  55. -moz-justify-content: center;
  56. -ms-justify-content: center;
  57. -o-justify-content: center;
  58. }
  59. .flexSb {
  60. justify-content: space-between;
  61. -webkit-justify-content: space-between;
  62. -moz-justify-content: space-between;
  63. -ms-justify-content: space-between;
  64. -o-justify-content: space-between;
  65. }
  66. .flexS {
  67. -webkit-box-pack: start;
  68. justify-content: flex-start;
  69. -webkit-justify-content: flex-start;
  70. -moz-justify-content: flex-start;
  71. -ms-justify-content: flex-start;
  72. -o-justify-content: flex-start;
  73. }
  74. .flexE {
  75. -webkit-box-pack: end;
  76. justify-content: flex-end;
  77. -webkit-justify-content: flex-end;
  78. -moz-justify-content: flex-end;
  79. -ms-justify-content: flex-end;
  80. -o-justify-content: flex-end;
  81. }
  82. .line1 {
  83. white-space: nowrap;
  84. overflow: hidden;
  85. text-overflow: ellipsis;
  86. }
  87. .commonHead {
  88. width: 100%;
  89. height: 128rpx;
  90. box-sizing: border-box;
  91. -webkit-box-sizing: border-box;
  92. -moz-box-sizing: border-box;
  93. overflow: hidden;
  94. position: relative;
  95. z-index: 10;
  96. }
  97. .commonHead-wrap {
  98. width: 100%;
  99. position: absolute;
  100. overflow: hidden;
  101. left: 0;
  102. bottom: 0;
  103. height: 45px;
  104. line-height: 45px;
  105. }
  106. .commonHead_left {
  107. width: 100rpx;
  108. height: 100%;
  109. position: absolute;
  110. left: 0;
  111. top: 0
  112. }
  113. .commonHead_left_back {
  114. width: 100%;
  115. height: 100%;
  116. background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADIEAYAAAD9yHLdAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAgY0hSTQAAeiYAAICEAAD6AAAAgOgAAHUwAADqYAAAOpgAABdwnLpRPAAAAAZiS0dEAAAAAAAA+UO7fwAAAAlwSFlzAAAASAAAAEgARslrPgAACrhJREFUeNrt3E2IlPcdwPH/M4o1rUklNJHapdDQYBWaZJ1dhfQg5KURjNFoNkXTHAq5iGkPekgJJCFrCw3SQCi6l1wsZJOaimslJVTydoigzuzS5tC0Ui9lWWvxhaohCdn59zCdpLUx7s7OM888z/P5XJadffvNHPbL7//MTAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACQltt237b7tt1f+crq0dWjq0eXLGneWqlkPRe9Kcl6AKDbkqRarVar1Q0bQgwxxK1bw+qwOqy+995wPBwPxxcvbn1nHIkjcWR6OiwPy8PyP/0peSl5KXnp8OH5N8y/Yf4Ne/ce23ps67Gt//hH1veIbAgIlEAzGN/5Tnw6Ph2f/vWvk+FkOBkeHGz7F24P28P2S5eSncnOZOeuXbXztfO187t3N78YY9b3l+4QECiw6oXqheqFe+8Nd4e7w92vvtq89atf7fgfejG8GF78zW8W3bHojkV3/PCH7yTvJO8kn3yS9f0nXfOzHgDovJVPrnxy5ZP33Rffj+/H98fGkpCEJCxcmNoffCw8Fh77wQ8urr+4/uL6f/6zeeOPf5z140C6bCBQIP1H+4/2H127NqkklaRy8GCyPdmebE8xHFcTQwzxvvvq4/Xx+vgf/pD140I6PLsCCqBnwtEyHIbD8M9/nvXjQroEBHKsdVTVM+FoeSY8E54ZGBjYNbBrYNeyZVmPQzpcA4Ecam0coRIqoZfCcYXGkcaRxpF77ml+9pe/ZD0PnWUDgRzp2Y3jagbDYBj85jezHoN02EAgB/KycVwpWZIsSZYsWpT1HKRDQKCHtTaOvIXjUzeGG8ONU1NZj0E6BAR6UF43jis17mrc1bjrj3/Meg7S4XUg0EN67um4c/LBB82PN91Ur9fr9Xrrc4rCBgI9IPdHVVd6I7wR3tizp764vri+WDiKSkAgQ0U5qvrUjrAj7JicrFyqXKpceu65rMchXQICGSjWUVUIcU/cE/d8+GHl0cqjlUc3bTpx8sTJEyfPns16LtIlINBFhTuqGggDYeDjj+PN8eZ488MP107WTtZOHj+e9Vh0h4vo0AWfhuOB8EB4YGysKOFoPNF4ovHEQw9N3DJxy8Qthw9nPRbdJSCQIuGgyAQEUiAclIGAQAcJB2UiINABwkEZCQjMgXBQZgICbRAOEBCYFeGAzwgIzIBwwP8TEPgCwgFXJyDwOYQDrk1A4L8IB8ycgEAQDmiHgFBq
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/219422
推荐阅读
相关标签
  

闽ICP备14008679号