提交 716fcaa8 编写于 作者: shutao-dc's avatar shutao-dc

resize-observer.uvue 新增隐藏box示例

上级 7c7ee0c9
<template> <template>
<view> <view>
<text>点击蓝色或红色方块区域会修改元素宽高</text> <text>点击蓝色或红色方块区域会修改元素宽高</text>
<view style="align-items: center; justify-content: center; margin: 10px;"> <view v-show="boxDisplay" style="align-items: center; justify-content: center; margin: 10px;">
<view style="width: 140px; height: 140px; background-color: blue; align-items: center; justify-content: center; padding: 5px;" id="outBox" @click="outBoxClick"> <view style="width: 140px; height: 140px; background-color: blue; align-items: center; justify-content: center; padding: 5px;" id="outBox" @click="outBoxClick">
<view style="width: 80px; height: 80px; background-color: red; padding: 5px;" id="innerBox" @click="innerBoxClick"></view> <view style="width: 80px; height: 80px; background-color: red; padding: 5px;" id="innerBox" @click="innerBoxClick"></view>
</view> </view>
</view> </view>
<button @click="revertBoxSize">还原修改前元素宽高</button> <button @click="revertBoxSize">还原修改前元素宽高</button>
<button @click="toggleDisplay">{{boxDisplay? '隐藏元素': '显示元素'}}</button>
<view> <view>
<text class="info-text">蓝色方块元素:</text> <text class="info-text">蓝色方块元素:</text>
<view class="info-item"> <view class="info-item">
...@@ -27,6 +28,7 @@ ...@@ -27,6 +28,7 @@
outBoxSizeInfo: "", outBoxSizeInfo: "",
innerBoxSizeInfo: "", innerBoxSizeInfo: "",
offset: 2, offset: 2,
boxDisplay: true,
outBoxElement: null as UniElement | null, outBoxElement: null as UniElement | null,
innerBoxElement: null as UniElement | null, innerBoxElement: null as UniElement | null,
} }
...@@ -65,6 +67,9 @@ ...@@ -65,6 +67,9 @@
this.innerBoxElement!.style.setProperty("height", "80px") this.innerBoxElement!.style.setProperty("height", "80px")
} }
}, },
toggleDisplay() {
this.boxDisplay = !this.boxDisplay
},
analysisResizeObserverEntry(entry: UniResizeObserverEntry): string { analysisResizeObserverEntry(entry: UniResizeObserverEntry): string {
const contentBoxSize = entry.contentBoxSize[0] const contentBoxSize = entry.contentBoxSize[0]
const borderBoxSize = entry.borderBoxSize[0] const borderBoxSize = entry.borderBoxSize[0]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册