文章目录
- 问题描述
问题描述
大家好!今天是
2024年4月26日|农历三月十六
,时间过得好快,今天这博文主要动态改变css样式,具体实现效果如下:
在data里面声明一个isShow:true
属性,通过isShow显示不同的图片
isShow:true,
oneImg:config.OBS+'/tou.jpg',
twoImg:config.OBS+'/qiehuan.jpg',
<image:src="isShow ? oneImg : twoImg":style="{ height: isShow ? '430rpx' : '330rpx', width: '100%' }"
></image>
在scrollChange
函数中动态赋值isShow
scrollChange(e) {if (scrollTop > this.scrollPosition) {// 如果滚动位置大于或等于图片高度,并且比上次滚动位置大,说明向上滑动this.isShow = false;shouldAdjustHeight = true;} else if (scrollTop < imageHeight && scrollTop < this.scrollPosition) {// 如果滚动位置小于图片高度,并且比上次滚动位置小,说明向下滑动this.isShow = true;shouldAdjustHeight = true;}
}
<view style="width: 220rpx"><yjy-switchstyle="width: 200rpx;float:right;"@switchFunction="switchChangeFun":switchType="'text'":defaultColor="'#31aa3c'":highColor="'#FFFFFF'":defaultValue="switchDefaultValue":switchList="switchListText":itemIndex="0"></yjy-switch>
</view>