position.uvue 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <!-- #ifdef APP -->
  3. <scroll-view style="flex: 1">
  4. <!-- #endif -->
  5. <view style="flex-grow: 1">
  6. <view>
  7. <text>position: fixed</text>
  8. <scroll-view style="width: 250px; height: 250px; background-color: gray">
  9. <view style="width: 50px; height: 50px; background-color: red"></view>
  10. <view class="common fixed" style="position: fixed">
  11. <text class="text">fixed</text>
  12. </view>
  13. <view style="width: 50px; height: 50px; background-color: blue"></view>
  14. <view style="width: 50px; height: 50px; background-color: red"></view>
  15. <view style="width: 50px; height: 50px; background-color: green"></view>
  16. <view style="width: 50px; height: 50px; background-color: blue"></view>
  17. <view style="width: 50px; height: 50px; background-color: red"></view>
  18. <view style="width: 50px; height: 50px; background-color: green"></view>
  19. <view style="width: 50px; height: 50px; background-color: blue"></view>
  20. </scroll-view>
  21. </view>
  22. <view>
  23. <text>position: relative</text>
  24. <scroll-view style="width: 250px; height: 250px; background-color: gray">
  25. <view style="width: 50px; height: 50px; background-color: red"></view>
  26. <view class="common" style="position: relative">
  27. <text class="text">relative</text>
  28. </view>
  29. <view style="width: 50px; height: 50px; background-color: blue"></view>
  30. <view style="width: 50px; height: 50px; background-color: red"></view>
  31. <view style="width: 50px; height: 50px; background-color: green"></view>
  32. <view style="width: 50px; height: 50px; background-color: blue"></view>
  33. <view style="width: 50px; height: 50px; background-color: red"></view>
  34. <view style="width: 50px; height: 50px; background-color: green"></view>
  35. <view style="width: 50px; height: 50px; background-color: blue"></view>
  36. </scroll-view>
  37. </view>
  38. <view>
  39. <text>position: absolute</text>
  40. <scroll-view style="width: 250px; height: 250px; background-color: gray">
  41. <view style="width: 50px; height: 50px; background-color: red"></view>
  42. <view class="common" style="position: absolute">
  43. <text class="text">absolute</text>
  44. </view>
  45. <view style="width: 50px; height: 50px; background-color: blue"></view>
  46. <view style="width: 50px; height: 50px; background-color: red"></view>
  47. <view style="width: 50px; height: 50px; background-color: green"></view>
  48. <view style="width: 50px; height: 50px; background-color: blue"></view>
  49. <view style="width: 50px; height: 50px; background-color: red"></view>
  50. <view style="width: 50px; height: 50px; background-color: green"></view>
  51. <view style="width: 50px; height: 50px; background-color: blue"></view>
  52. </scroll-view>
  53. </view>
  54. </view>
  55. <!-- #ifdef APP -->
  56. </scroll-view>
  57. <!-- #endif -->
  58. </template>
  59. <style>
  60. .common {
  61. width: 50px;
  62. height: 50px;
  63. background-color: green;
  64. top: 25px;
  65. left: 25px;
  66. justify-content: center;
  67. align-items: center;
  68. }
  69. .fixed {
  70. /* #ifdef WEB*/
  71. top: calc(var(--uni-safe-area-inset-top) + 25px);
  72. left: calc(var(--uni-safe-area-inset-left) + 25px);
  73. /* #endif */
  74. }
  75. .text {
  76. white-space: nowrap;
  77. width: 100%;
  78. }
  79. </style>