• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

uni-app h5动态设置元素的高度

武飞扬头像
mb63b53e13a8581
帮助1

<view class="page-box">
	<view class="fixed-box"></view>
	<scroll-view :style="{height:scrollHeight}" scroll-y="true"></scroll-view>
</view>

需求:根据屏幕的高度和fixed-box的高度计算scroll-view的高度

<script lang="ts" setup>
	const scrollHeight = ref('')
	const calculateHeight = ()=>{
		let windowHeight = null
	    let fixedHeight = 0
	    let paginationHeight = 0
	    uni.getSystemInfo({ //获取屏幕高度
	      success: res => {
	      	console.log("屏幕高度:", res.windowHeight) //res.windowHeight是返回的屏幕高度
	        windowHeight = res.windowHeight; 
	      }
	    });
	    // 获取元素高度
	    let query = uni.createSelectorQuery().in(instance); 
	    query.select('.fixed-box').boundingClientRect();
	    query.exec(res => {
	       console.log('元素高度',res[0].height)// 返回的值可以用作动态修改元素的高度
	       fixedHeight = res[0].height; 
	      
	    });
	    scrollHeight.value = windowHeight - fixedHeight   'px'
		}
	
</script>

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhibgijf
系列文章
更多 icon
同类精品
更多 icon
继续加载