1、获取元素的样式
使用wx.createSelectorQuery()来获取元素
这里需要注意的是:获取元素样式的函数应该放在onReady:function(){}这个里面
let that = this const query = wx.createSelectorQuery() query.select('.detail-card').boundingClientRect() query.select('.detail-header').boundingClientRect() query.exec((res => { that.setData({ cardHeight: res[0].height, headerHeight: res[1].height }) }))
2、修改元素的样式
这里思路是WXML中元素的样式利用style给一个变量,通过修改topList这个数组来修改top属性
<view class="detail-card" style="top:{{topList[index]+'px'}};z-index:{{index}}" id="{{'card'+index}}" wx:for="{{people}}" wx:key="{{index}}" catchtap="cardClick" > </view>
PHP中文网,大量免费小程序开发教程,欢迎学习!
以上就是小程序如何改变元素的样式的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号