es-nav-bg.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <view>
  3. <!-- <view class="bg-img" style="position: absolute;top:0;width: 100%;height: 600rpx;background-image: url(/static/image/home/home_top_bg.png)"></view> -->
  4. <image src="/static/image/home/home_top_bg.png" style="width: 100%;position: absolute;top:0;left:0;z-index: 0;" mode="widthFix"></image>
  5. <block v-if="title">
  6. <view class="es-fix-top" :class="css">
  7. <view class="" :style="top_color?('background:'+top_color):''" id="div-top">
  8. <es-top></es-top>
  9. <es-nav-title-base :title="title"></es-nav-title-base>
  10. </view>
  11. </view>
  12. <es-top></es-top>
  13. <view class="es-h-88"></view>
  14. </block>
  15. <block v-else>
  16. <view class="es-fix-top" :class="css">
  17. <view class="" :style="top_color?('background:'+top_color):''" id="div-top">
  18. <es-top></es-top>
  19. <slot></slot>
  20. </view>
  21. </view>
  22. </block>
  23. </view>
  24. </template>
  25. <script>
  26. export default {
  27. name: "es-nav-bg",
  28. data() {
  29. return {
  30. top_color: 'rgba(0,0,0,0)',
  31. h: 64,
  32. };
  33. },
  34. props: [
  35. 'title', 'css'
  36. ],
  37. created: function() {
  38. if (!this.title) {
  39. setTimeout(e => {
  40. try {
  41. uni.createSelectorQuery().select('#div-top').boundingClientRect(r2 => {
  42. if (r2) {
  43. this.h = r2.height;
  44. }
  45. }).exec();
  46. } catch (e) {
  47. //TODO handle the exception
  48. }
  49. }, 50)
  50. } else {
  51. }
  52. },
  53. methods: {
  54. scrollBody: function(e) {
  55. let top = e.scrollTop / this.h;
  56. this.top_color = 'rgba(255,92,3, ' + top + ')';
  57. }
  58. }
  59. }
  60. </script>
  61. <style>
  62. .bg-img {
  63. /* background-image: url(@/static/image/home/home_top_bg.png); */
  64. background-size: 100% auto;
  65. background-repeat: no-repeat;
  66. }
  67. </style>