如何通过小程序调整元素的具体样式?
- 内容介绍
- 文章标签
- 相关推荐
本文共计278个文字,预计阅读时间需要2分钟。
1. 获取元素样式使用 wx.createSelectorQuery() 获取元素注意事项:获取元素样式的方法应放在 onReady() 函数中:function() {let that=thisconst query=wx.createSelectorQuery()query.select('')
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中文网,大量免费小程序开发教程,欢迎学习!
以上就是小程序如何改变元素的样式的详细内容,更多请关注自由互联其它相关文章!
本文共计278个文字,预计阅读时间需要2分钟。
1. 获取元素样式使用 wx.createSelectorQuery() 获取元素注意事项:获取元素样式的方法应放在 onReady() 函数中:function() {let that=thisconst query=wx.createSelectorQuery()query.select('')
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中文网,大量免费小程序开发教程,欢迎学习!
以上就是小程序如何改变元素的样式的详细内容,更多请关注自由互联其它相关文章!

