uniapp按下上下滑动显示水位

<view class="huadong">
			<view class="ltshui">
				<view class="container">
					<view class="water-container" :style="{ backgroundImage: getWaterGradient(waterLevel) }"
						@touchstart="onTouchStart" @touchmove="onTouchMove" @touchend="onTouchEnd" />
				</view>
			</view>
			<view class="zuis">
				<view class="xian"></view>
				<view class="pc">最少排出量</view>
				<view class="zuid">
					<view class="xian"></view>
					<view class="pc">最多排出量</view>
				</view>
			</view>
			<view class="rtshui">
				<view class="tit">
					拖动可调节水位
				</view>
				<view class="wary">
					当排水到达设定水位时,将从 化盐桶中抽水补给
				</view>
				<view class="rl">
					<text></text> 表示水缸的容量
				</view>
				<view class="sw">
					<text></text> 表示水缸的水位线
				</view>
			</view>
		</view>
        
		<view class="quer">
			确认换水
		</view>
	</view>

		.huadong {
			display: flex;
			margin-top: 36rpx;
			position: relative;
			.rtshui{
				.tit{
					font-size: 32rpx;
					color: #FFFFFF;
					margin-top: 32rpx;
				}
				.wary{
					font-size: 28rpx;
					color: #D8D8D8;
					margin-top: 14rpx;
				}
				.rl{
					font-size: 24rpx;
					color: #D8D8D8;
					margin-top: 82rpx;
					display: flex;
					align-items: center;
					text{
						display: inline-block;
						width: 32rpx;
						height: 32rpx;
						background: rgba(0,0,0,0.5);
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						border: 2rpx solid;
						border-image: linear-gradient(180deg, rgba(255, 255, 255, 0.07999999821186066), rgba(156.31499379873276, 140.25000303983688, 255, 0.23999999463558197)) 2 2;
						margin-right: 14rpx;
					}
				}
				.sw{
					font-size: 24rpx;
					color: #D8D8D8;
					margin-top: 36rpx;
					display: flex;
					align-items: center;
					text{
						display: inline-block;
						width: 32rpx;
						height: 32rpx;
						background: #4B5991;
						border-radius: 4rpx 4rpx 4rpx 4rpx;
						margin-right: 14rpx;
					}
				}
			}
			.zuis {
				margin-top: 50rpx;

				.zuid {
					margin-top: 108rpx;

					.xian {
						width: 40rpx;
						height: 2rpx;
						background-color: #D8D8D8;
						margin-left: -20rpx;
					}

					.pc {
						font-size: 24rpx;
						color: #FFFFFF;
						margin-top: 6rpx;
						margin-left: 6rpx;
						width: 180rpx;
					}
				}

				.xian {
					width: 40rpx;
					height: 2rpx;
					background-color: #D8D8D8;
					margin-left: -20rpx;
				}

				.pc {
					font-size: 24rpx;
					color: #FFFFFF;
					margin-top: 6rpx;
					margin-left: 6rpx;
					width: 180rpx;
				}
			}

			.ltshui {
				.container {
					display: flex;
					justify-content: center;
					align-items: center;

					.water-container {
						width: 148rpx;
						height: 344rpx;
						background: rgba(0, 0, 0, 0.5);
						border-radius: 24rpx 24rpx 24rpx 24rpx;
						background-size: 100% 100%;
						background-repeat: no-repeat;
					}
				}
			}
		}


<script>
	export default {
		data() {
			return {
				rttcflag: false,
				indexactive: 1,
				num: 1,
				txtwz: '',

				startY: 0,
				deltaY: 0,
				waterLevel: 40,
				isDragging: false,
			}
		},
		onLoad() {

		},
		methods: {
			onTouchStart(e) {
				this.startY = e.touches[0].clientY
				this.isDragging = true
			},
			onTouchMove(e) {
				if (!this.isDragging) return
				const currentY = e.touches[0].clientY
				this.deltaY = currentY - this.startY
				if (this.deltaY > 0) {
					this.waterLevel = Math.min(this.waterLevel + this.deltaY * 0.5, 100) //每次滑动1px增加0.5%的水位  
				} else if (this.deltaY < 0) {
					this.waterLevel = Math.max(this.waterLevel + this.deltaY * 0.5, 0)
				}
				// console.log(this.waterLevel)
				this.startY = currentY
			},
			onTouchEnd() {
				this.isDragging = false
			},
			getWaterGradient(level) {
				const gradient =
					`linear-gradient(to bottom, rgba(0,0,0,0.5) ${level}%, rgba(101, 121, 199, 0.7) ${level}%, rgba(101, 121, 199, 0.7) 100%)`
				return gradient
			},

			
			
		}
	}
</script>

最后效果

相关推荐
叁分之一4 分钟前
“我打包又失败了”
前端·npm
tang游戏王1234 分钟前
AJAX进阶-day4
前端·javascript·ajax
无语听梧桐9 分钟前
vue3中使用Antv G6渲染树形结构并支持节点增删改
前端·vue.js·antv g6
go2coding28 分钟前
开源 复刻GPT-4o - Moshi;自动定位和解决软件开发中的问题;ComfyUI中使用MimicMotion;自动生成React前端代码
前端·react.js·前端框架
freesharer1 小时前
Zabbix 配置WEB监控
前端·数据库·zabbix
web前端神器1 小时前
forever启动后端服务,自带日志如何查看与设置
前端·javascript·vue.js
是Yu欸1 小时前
【前端实现】在父组件中调用公共子组件:注意事项&逻辑示例 + 将后端数组数据格式转换为前端对象数组形式 + 增加和删除行
前端·vue.js·笔记·ui·vue
今天是 几 号1 小时前
WEB攻防-XSS跨站&反射型&存储型&DOM型&标签闭合&输入输出&JS代码解析
前端·javascript·xss
A-超1 小时前
html5 video去除边框
前端·html·html5
进击的阿三姐2 小时前
vue2项目迁移vue3与gogocode的使用
前端·javascript·vue.js