123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <template>
- <view style="flex-grow: 1;">
- <view style="position:absolute;z-index:0;">
- <view class="common fixed default">
- <text>position: fixed</text>
- <text>z-index: 10</text>
- </view>
- <view class="common fixed specified">
- <text>position: fixed</text>
- <text>z-index: 5</text>
- </view>
- <view class="common fixed floor">
- <text>position: fixed</text>
- <text>z-index: -1</text>
- </view>
- </view>
- <view style="top: 250px;">
- <view class="common" style="background-color: red;z-index: 10;">
- <text>z-index: 10</text>
- </view>
- <view ref="view" class="common" style="background-color: green;z-index: 5;top: -37px;left: 87px;"
- @click="changeZIndex(20)">
- <text>z-index: {{zIndex}}</text>
- <text>点击修改z-index</text>
- </view>
- <view class="common" style="background-color: blue;top: -75px;left: 175px;">
- <text>z-index: 0</text>
- </view>
- </view>
- <view>
- <view>
- <view class="common fixed popup" style="background-color: aqua;z-index: 5;">
- <text>position: fixed</text>
- <text>z-index: 5</text>
- </view>
- </view>
- </view>
- </view>
- <view v-if="autoTest">
- <view style="z-index: 1;position: fixed;">111</view>
- <view style="width: 750rpx;">222</view>
- </view>
- </template>
- <script>
- export default {
- data () {
- return {
- zIndex: 5,
- // 自动化测试
- autoTest: false
- }
- },
- methods: {
- changeZIndex (zIndex: number) {
- this.zIndex = 20;
- (this.$refs['view'] as UniElement).style.setProperty('z-index', zIndex);
- }
- }
- }
- </script>
- <style>
- .common {
- width: 125px;
- height: 125px;
- justify-content: center;
- align-items: center;
- }
- .fixed {
- position: fixed;
- }
- .default {
- background-color: red;
- z-index: 10;
- top: var(--uni-safe-area-inset-top);
- left: var(--uni-safe-area-inset-left);
- }
- .specified {
- background-color: green;
- z-index: 5;
- /* #ifdef APP || MP */
- top: 87px;
- left: 87px;
- /* #endif */
- /* #ifdef WEB */
- top: calc(var(--uni-safe-area-inset-top) + 87px);
- left: calc(var(--uni-safe-area-inset-left) + 87px);
- /* #endif */
- }
- .floor {
- background-color: chocolate;
- /* #ifdef APP || MP */
- top: 250px;
- left: 175px;
- /* #endif */
- /* #ifdef WEB */
- top: calc(var(--uni-safe-area-inset-top) + 250px);
- left: calc(var(--uni-safe-area-inset-left) + 175px);
- /* #endif */
- z-index: -1;
- }
- .popup {
- /* #ifdef APP || MP */
- top: 320px;
- left: 87px;
- /* #endif */
- /* #ifdef WEB */
- top: calc(var(--uni-safe-area-inset-top) + 320px);
- left: calc(var(--uni-safe-area-inset-left) + 87px);
- /* #endif */
- height: 40px;
- }
- </style>
|